[Tutor] Beginner's guessing game
Can u please tell me why this program does not work in line 28? That is guessesTaken. It reads 0 when it should be a larger number. I am a beginner having another try to get it! Thank you, Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 148, Issue 20
I was 63 when I started. It's never too late. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Study Tips
Gday! On 31/05/2016 8:52 AM, "Steve Lett" <steve.lett...@gmail.com> wrote: > Thank you for the reply. > On 30/05/2016 3:45 PM, "Steve Lett" <steve.lett...@gmail.com> wrote: > >> Hi folks, >> Just started learning python. I've been having a really hard time in >> getting started, and still am! I have a slight learning difficulty, >> including a stroke in Jan.2010. You wouldnt know even if u were here >> looking at me! Praise God for the great salvation! >> I have a slight learning difficulty. Has anyone got any tips on how to >> study programming and what approach would be best for me? >> >> Out of a long list of books that I have collected ( python, Blender, etc >> ) I have decided to start on Introducing Python (hard copy 2nd Ed, ebook >> 3rd ed) by Bill Lubanovic. Before that I was going to start with Python >> Programming for the Absolute Beginner, Michael Dawson. >> >> Any thoughts on these issues and especially the study tips already >> mentioned. >> >> Thank you, Steve >> > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Study Tips
Thank you for the reply. On 30/05/2016 3:45 PM, "Steve Lett" <steve.lett...@gmail.com> wrote: > Hi folks, > Just started learning python. I've been having a really hard time in > getting started, and still am! I have a slight learning difficulty, > including a stroke in Jan.2010. You wouldnt know even if u were here > looking at me! Praise God for the great salvation! > I have a slight learning difficulty. Has anyone got any tips on how to > study programming and what approach would be best for me? > > Out of a long list of books that I have collected ( python, Blender, etc ) > I have decided to start on Introducing Python (hard copy 2nd Ed, ebook 3rd > ed) by Bill Lubanovic. Before that I was going to start with Python > Programming for the Absolute Beginner, Michael Dawson. > > Any thoughts on these issues and especially the study tips already > mentioned. > > Thank you, Steve > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Study Tips
Hi folks, Just started learning python. I've been having a really hard time in getting started, and still am! I have a slight learning difficulty, including a stroke in Jan.2010. You wouldnt know even if u were here looking at me! Praise God for the great salvation! I have a slight learning difficulty. Has anyone got any tips on how to study programming and what approach would be best for me? Out of a long list of books that I have collected ( python, Blender, etc ) I have decided to start on Introducing Python (hard copy 2nd Ed, ebook 3rd ed) by Bill Lubanovic. Before that I was going to start with Python Programming for the Absolute Beginner, Michael Dawson. Any thoughts on these issues and especially the study tips already mentioned. Thank you, Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] While loop issue, variable not equal to var or var
Hey guys n gals, New to python, having some problems with while loops, I would like to make a program quick once q or Q is typed, but thus far I can only get the first variable to be recognized. My code looks like: message = raw_input(- ) while message != 'q': s.send(message) data = s.recv(2048) print str(data) message = raw_input(- ) s.close() print(Shutting Down) I've tried: while message != 'q' or 'Q': while message != 'q' or message != 'Q': while message != ('q' or 'Q'): Any ideas would be much appreciated! Thanks! :D Regards, Steve Rodriguez ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] While loop issue, variable not equal to var or var
Thank you guys! Works perfectly! :D Regards, Steve Rodriguez On Sat, Jul 12, 2014 at 1:21 AM, Peter Otten __pete...@web.de wrote: Peter Otten wrote: PS: You sometimes see message in qQ but this is buggy as it is true when the message is either q, Q, or qQ. Oops, I forgot . ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Regular expression - I
The problem is not the use of the raw string, but rather the regular expression inside it. In regular expressions, the * means that whatever appears before it may be repeated zero or more times. So if you say H* that means zero or more H’s in a row. I think you mean an H followed by any number of other characters which would be H.* (the . matches any single character, so .* means zero or more of any characters). On the other hand, H\* means to match an H followed by a literal asterisk character. Does that help clarify why one matched and the other doesn’t? steve On 18-Feb-2014, at 10:09, Santosh Kumar rhce@gmail.com wrote: Steve, i am trying to under r - raw string notation. Am i understanding it wrong. Rather than using \, it says we can use the r option. http://docs.python.org/2/library/re.html Check the first paragraph for the above link. Thanks, santosh On Tue, Feb 18, 2014 at 11:33 PM, Steve Willoughby st...@alchemy.com wrote: Because the regular expression H* means “match an angle-bracket character, zero or more H characters, followed by a close angle-bracket character” and your string does not match that pattern. This is why it’s best to check that the match succeeded before going ahead to call group() on the result (since in this case there is no result). On 18-Feb-2014, at 09:52, Santosh Kumar rhce@gmail.com wrote: Hi All, If you notice the below example, case I is working as expected. Case I: In [41]: string = H*testH* In [42]: re.match('H\*',string).group() Out[42]: 'H*' But why is the raw string 'r' not working as expected ? Case II: In [43]: re.match(r'H*',string).group() --- AttributeErrorTraceback (most recent call last) ipython-input-43-d66b47f01f1c in module() 1 re.match(r'H*',string).group() AttributeError: 'NoneType' object has no attribute 'group' In [44]: re.match(r'H*',string) Thanks, santosh ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- D. Santosh Kumar RHCE | SCSA +91-9703206361 Every task has a unpleasant side .. But you must focus on the end result you are producing. signature.asc Description: Message signed with OpenPGP using GPGMail ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Regular expression - I
Because the regular expression H* means “match an angle-bracket character, zero or more H characters, followed by a close angle-bracket character” and your string does not match that pattern. This is why it’s best to check that the match succeeded before going ahead to call group() on the result (since in this case there is no result). On 18-Feb-2014, at 09:52, Santosh Kumar rhce@gmail.com wrote: Hi All, If you notice the below example, case I is working as expected. Case I: In [41]: string = H*testH* In [42]: re.match('H\*',string).group() Out[42]: 'H*' But why is the raw string 'r' not working as expected ? Case II: In [43]: re.match(r'H*',string).group() --- AttributeErrorTraceback (most recent call last) ipython-input-43-d66b47f01f1c in module() 1 re.match(r'H*',string).group() AttributeError: 'NoneType' object has no attribute 'group' In [44]: re.match(r'H*',string) Thanks, santosh ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help how to run it on python 3.3
You might want to check out the '2to3' program to convert Python 2.x code to Python 3.x code. The following command worked to change your code to runnable Python 3.x code: 2to3 -w your file containing 2.x code -- Steve Mayer smaye...@me.com On 8 Jan 2014, at 10:19, S Tareq wrote: need help how to run it on python 3.3, or change it to python 3.3 when i run it says syntax error if i run it on python 2.7 it works. # Import statements import random import datetime #Arrays to store the definitions and keywords read from the file keywords=[]; definition=[]; correctAnswer=[]; #Counter for the wrong Answer and counter of number of definition in correctAnswerCounter=0 wrongAnswer=0; counter=0; # Taking User input for accepting the file name to be read filename= raw_input(Enter the File Name with extension) #Reading the file from start to the end for line in open(filename,'r').readlines(): if(counter%2==0): keywords.append(line); counter=counter+1; correctAnswer.append(0) else: definition.append(line); keys=[]; keys=line.split( ); counter=counter+1; # Running two while loops to make the pattern recursive while True: # Starting the time for quiz and also, creating variables to make sure that same sequences and answers are not repeated a = datetime.datetime.now().replace(microsecond=0) prevWord=0 prevSeq=0 # While loop to run the code till each answer is correctly answered while correctAnswer.count(2)!=(counter/2): #While loop to generate an different random number from one the generated previously while True: word=random.randint(0,(counter/2)-1) if(correctAnswer[word]!=2): break; if(prevWord==word): continue; # Displaying the new keyword each time. print Please Select the number which is the correct definition of the word: ,keywords[word] #Generating an new sequence each time different from previous one while True: sequences =random.randint(0,2) if(prevSeq==sequences): continue; else: break #Generating an new incorrect answer each time different from previous one while True: incorrectAnswer=random.randint(0,len(correctAnswer)-1) if(incorrectAnswer==word): continue; else : break #Generating an new incorrect answer each time different from previous one while True: incorrectAnswerSecond=random.randint(0,len(correctAnswer)-1); if (incorrectAnswer==incorrectAnswerSecond): continue if(incorrectAnswerSecond==word): continue else: break # Displaying the options to the user based on the sequence number generated if (sequences==0): print 1.,definition[word] print 2.,definition[incorrectAnswer] print 3.,definition[incorrectAnswerSecond] elif (sequences==1): print 1.,definition[incorrectAnswer] print 2.,definition[incorrectAnswerSecond] print 3.,definition[word] elif (sequences==2): print 1.,definition[incorrectAnswerSecond] print 2.,definition[word] print 3.,definition[incorrectAnswer] #Taking the answer from user answer = raw_input(Enter the Correct Number between 1 to 3) # Assign the seq and word to preseq and word prevSeq=sequences prevWord=word #Checking the answer if they are corret. if(0 == sequences): if(answer == 1): print success correctAnswer[word]=correctAnswer[word]+1 correctAnswerCounter=correctAnswerCounter+1 else: print Wrong Answer print Correct Answer: ,definition[word] wrongAnswer=wrongAnswer+1; elif(1 == sequences): if(answer == 3): print success correctAnswer[word]=correctAnswer[word]+1 correctAnswerCounter=correctAnswerCounter+1 else: print Wrong Answer print Correct Answer: ,definition[word] wrongAnswer=wrongAnswer+1; elif(2 == sequences): if(answer == 2): print success correctAnswer[word]=correctAnswer[word]+1 correctAnswerCounter=correctAnswerCounter+1 else: print Wrong Answer print Correct Answer: ,definition[word] wrongAnswer=wrongAnswer+1 # Stopping the time of the clock b = datetime.datetime.now().replace(microsecond=0) # displaying number of wrong answer and total quiz time print Total Number of Wrong Answer
Re: [Tutor] Subprocess communications query
Reuben reuben.dl...@gmail.com wrote: I want to implement a python script on machine A to do telnet/ssh into machine B (this might be easy)and then run the Test.py (this is challenging) On 11-Dec-2013 1:05 AM, Danny Yoo d...@hashcollision.org wrote: On Tue, Dec 10, 2013 at 11:28 AM, Reuben reuben.dl...@gmail.com wrote: Hi, There exists two Linux machines A and B. Machine B contains python script which needs to be run e.g. Test.py In order to run that script, machine A needs to telnet into machine B and then execute python Test.py Nothing about this sounds like Python. Is there anything specifically Python-related to this question, besides the detail that machine B is running a Python program? This really sounds like more like a Linux system administration question. If that's the case, you probably want to ask on a forum for system administrators, like: http://unix.stackexchange.com/ where they'll be able to point you in a better direction than us. (By the way, when you say telnet, I do hope you do not literally mean telnet, which is not known to be secure. You need to talk with other system administrators and learn about tools like ssh.) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor You could do many different things depending on your needs. You could write a daemon in python on one machine which waits for a python program on the other to command it to run a process. You could find out how to accomplish this using ssh and then just write a python script to execute that ssh command for you. Without more details it's hard too say what is more appropriate but I would suggest reading up on python subprocess module, ssh, and internet protocol and server modules in the standard library. -- Sent from my Android device with K-9 Mail. Please excuse my brevity.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Removing Unnecessary Indentation and other problems
On your first question, make sure you have the right version of Tcl/Tk for your system (usually a tar.gz file is for Unix-like systems, although some programs like WinZip can read those files too). You may be able to get help from a Tcl/Tk forum on specifics of building that. However, doesn't your Python installation come with tkinter included? Most do. On your second question, the issue is that your program is inserting some kind of spaces or tabs when printing out that dictionary. How are you printing it? Include the actual code of your program please when asking questions about it so we know what's going on. Generally, though, you will want to use a formatted print statement such as the % operator with print, or the .format() method with print. It looks like you're printing a tab between the key and value, which is going to produce output like that if the keys don't fit within a single tab zone (8 characters usually). HTH HAND steve On 15-Nov-2013, at 14:44, harvey trasmontero harveytrasmont...@hotmail.com wrote: Good day, I have two problems. First one is, using and downloading tkinter. I have searched about it and it led me to a download page. But then, I didnt know which one to download so I chose the first one on the right. It led me to a zip file and its saying extract the'.tar.gz files for tcl and tk' but I couldn't find it in the zip file that I downloaded. What do I do? Secondly, I am having a hard time finding an answer to my question, which is how to remove indentation on dictionary when I run my program. I've searched google and all but I couldnt find anything. So the dictionary kind of looks like this: Dic = {Sunnynook Rd:'50',Carlisle Rd:'50',East Coast Rd:'50',Upper Harbour Drive:'50', Lake Rd:'50',Waipa St:'50',Great North Rd:'50',Richardson Rd:'50',Atkinson Rd:'50'} My problem is when I run my program, there are unnecessary indentations in Upper Harbour Drive and Lake Rd. So when I run it it looks like this: Atkinson Rd50 Carlisle Rd 50 Lake Rd 50 Upper Harbour Drive50 Waipa St 50 Sunnynook Rd 50 Richardson Rd50 Great North Rd 50 East Coast Rd 50 How do I align Lake Rd and Upper Harbour Drive so it wont look silly like the one above? Thank you and hope to hear from one of you tutors Regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Nested lists help
On 18-Oct-2013, at 17:13, Corinne Landers corinne.land...@live.com wrote: self.grid_x = x self.grid_y = y self.grid_z = z self.grid = [] self.grid2D = [] So here you create a list, self.grid2D. for i in range(self.grid_y): row = [0]*x self.grid2D.append(row) Here you are adding more elements to that list. for k in range(z): self.grid.append(self.grid2D) #Creates list of x by y grids But here you keep appending self.grid2D multiple times to self.grid. Not z different copies, but they're all the exact name list object, referenced multiple times.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] postgresql was: Re: Tutor Digest, Vol 115, Issue 6
On 04-Sep-2013, at 14:28, Alan Gauld alan.ga...@btinternet.com wrote: On 03/09/13 08:25, Ismar Sehic wrote: help with postgres and csv: i solved my problem by playing with the sql line a little. it looked like this : sql = UPDATE hotel SET path_picture = +';+hotel_url+' WHERE code LIKE '+%+hotel_code+' now it's like this : UPDATE hotel SET path_picture = ' + hot_url + ' WHERE code LIKE '% + hot_code + '; i guess the problem was in building the sql string, but i don't yet quite understand what i did.can someone point me to some online resorces about postgres and python integration? https://wiki.python.org/moin/PostgreSQL While you're looking at all the information Alan pointed you to, consider one other general bit of advice when programming with SQL queries. It is generally a very convenient trick to use string formatting or string catenation to build the bits of your query from pieces, like you did above (UPDATE … SET path_picture=' + hot_url + …). Convenient, but a very, very bad idea in practice. This makes your program vulnerable to SQL injection, which in many cases can have devastating effects when someone exploits it. Assuming that the variables come from sources beyond your control (and even if they are--at the moment--generated by you), use parameterized queries (look for those in your API libraries). They usually look something like the following (although specifics can vary), where you leave a placeholder character like ? in the SQL string, and supply the data values separately. Unlike using string-maniputation features of Python, the database API knows exactly how to properly include those data values into the SQL command for you: some_api_function_to_do_sql(UPDATE hotel SET path_picture = ? WHERE code LIKE ?, hot_url, '%' + hot_code + '%') --steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Unix Environment variables
Note, however, that changing environment variables only affects the environment of your script and it's child processes. Once your script exits, the original shell you called it from is NOT changed. Sent from my iPad On 2013/6/23, at 14:35, Amit Saha amitsaha...@gmail.com wrote: Hello, On Tue, Jun 18, 2013 at 9:58 AM, Anu Bhagat abha...@seti.org wrote: Hi I am fairly new to python. I will greatly appreciate if some one can tell me how set up environment variables from a python script. Thanks in advance. You can use the 'os' module. This is the document for Python 2 [1]. That should help you retrieving/setting environment variables. [1] http://docs.python.org/2/library/os.html#os.environ Best, Amit. Anu -- Nothing is impossible, the word itself says 'I'm possible'. Audrey Hepburn Anu Bhagat SETI Institute 189 North Bernardo Street Mountain View, CA 94043-5203 Phone : 650.960.4592 Fax : 650.960.5830 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- http://echorand.me ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python web related scripts needed
On 12-Jun-2013, at 05:48, Manigopal Vepati manigopa...@gmail.com wrote: Hi, I need scripts for the following . 1) check whether username and password fields are present in Gmail 2) Code to access the system which doesn’t have ip address And what have you found as you've started writing those scripts? Anything in particular you've run into that you're puzzled by? This list can be a wonderful resource to assist you as you learn to write your first scripts, but please remember that it is staffed by volunteers who take their valuable personal time to help others learn. We're not here to perform contract programming for you, or to do homework for you, just to help you along the way as you learn to program in Python. When you do get to a point where you need help, you need to be sure to ask meaningful questions and provide as much background information as would be needed for someone to truly understand what you're doing. For example, in the message you sent, it's impossible to know what you're even trying to accomplish because you don't say what you mean by fields present in Gmail (I can think of a dozen completely different things that could mean, and you don't give enough information to actually be able to move forward with any of them even were I to guess which of them you intended. I can't even make sense of the second one at all. You don't say what kind of access you're referring to, or what IP address has to do with anything (e.g., are you asking how to look up an IP address in DNS, or that the system isn't on a standard network which uses IP protocols, or what). Assuming that you have your programming goals better developed than is apparent in your email, make a good start at your implementation and then tell us in detail what you get stuck with. And just because we tend to get asked this from time to time, in case what you mean here is to somehow hack or illegally access a system you aren't otherwise allowed to access, we won't help you at all with anything like that. Don't bother even asking. i am using python 3.3 Ok, that's a very valuable piece of information. Since you're also accessing resources outside your scripts (other machines and mail services), it would also be useful to know the operating system and version of the systems involved. thanks manigopal ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi, First question
On 16-Jun-2013, at 09:21, Mark Lawrence breamore...@yahoo.co.uk wrote: On 16/06/2013 16:55, Chris “Kwpolska” Warrick wrote: On Sat, Jun 15, 2013 at 7:22 AM, Patrick Williams pdw0...@gmail.com wrote: Hi so I am making a bit of code to extract a bit of numbers data from a file and then find the average of that data, however while I can get the code to extract each specific piece of data I need, I can't seem to get the numbers to add separately so I can get a proper average. My sum1 variable seems to only take the last bit of data entered. I was just wondering if anyone knows what I'm doing wrong, the course I'm following hadn't started using regex (or even proper lists) at this point, so there must be a way to do it without. here's the code. the average of the data should be 0.6789 or something, but I get 0.0334343 or something. count=0 lst=list() `lst = []` is the preferred syntax. fname='mbox-short.txt' fhand=open(fname) for line in fhand: if line.startswith('X-DSPAM-Confidence:'): count=count+1 colpos=line.find(':') zpos=line.find('0',colpos) num=float(line[zpos:50]) sum1=0+num avg=float(sum1)/int(count) I'll assume unless someone tells me differently that sum1 does not need reinitialising every time, and that avg needs to be calculated when the loop has finished. print 'Count-', count,'--', 'Average-', avg Any help at all is appreciated, and thanks in advance. I don’t know what file you used, but the message you sent got this header from Gmail, and the format doesn’t seem to be much different: X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'separately': 0.09; 'wrong,': 0.09; 'subject:question': 0.10; 'code.': 0.18; 'variable': 0.18; 'bit': 0.19; 'advance.': 0.19; 'seems': 0.21; '8bit%:5': 0.22; 'print': 0.22; 'skip:l 30': 0.24; '\xa0so': 0.24; [snip 11 more lines] (replaced tabstops with spaces) Can you guess what’s wrong in your code? You are reading only the first line. What does for line in fhand: do then? I think what that was referring to was the assumption that you're reading mail header lines from that file, and they can be split out over multiple lines (see the example cited above). If that's the case, then for line in fhand will iterate over each line in the file, but you're only looking for lines which start with X-Spam-.. which would only be the FIRST part of the header if it's split out like that. If your file is NOT organized like that, then your situation is different. However, if your files are like that, you're going to randomly miss data if the fields you're looking for don't happen to be on the first line of the multi-line header. Now if you are reading RFC-822 (et al) standard mail messages in those files, there are bits of the Python standard library which will be immensely useful to you in parsing out those headers rather than trying to do it yourself. That's something you're going to find to be the case frequently with Python. -- Steve is going for the pink ball - and for those of you who are watching in black and white, the pink is next to the green. Snooker commentator 'Whispering' Ted Lowe. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there a programmatic use for keys() and values()
On 16-Jun-2013, at 10:49, Jim Mooney cybervigila...@gmail.com wrote: On 16 June 2013 01:43, Roel Schroeven r...@roelschroeven.net wrote: Can't you disable that behavior somewhere in the settings of your IDE? I know IDEs do that to be helpful, but I don't like it and so far I've been able to disable it in all IDEs I've used. VIM sounds good but I don't think there's a version for Windows. There's a version of VIM for about everything, including Windows and OS X. As for the one-week learning curve on VIM, reminds me of that claim for Joomla. Yes, you can set up a site in a few hours after your first install of Joomla, but learning to fix the blowups and problems while people are screaming at you, since it's all public, takes considerably longer. Although an editor that's been around since the stone age probably doesn't blow up. I doubt VIM has a constant stream of upgrades (not always compatible), bug fixes, and security fixes ;') Yeah, at this point it's pretty stable. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Is there a programmatic use for keys() and values()
On 16-Jun-2013, at 11:35, Steven D'Aprano st...@pearwood.info wrote: On 17/06/13 03:59, Steve Willoughby wrote: On 16-Jun-2013, at 10:49, Jim Mooney cybervigila...@gmail.com wrote: On 16 June 2013 01:43, Roel Schroeven r...@roelschroeven.net wrote: Can't you disable that behavior somewhere in the settings of your IDE? I know IDEs do that to be helpful, but I don't like it and so far I've been able to disable it in all IDEs I've used. VIM sounds good but I don't think there's a version for Windows. There's a version of VIM for about everything, including Windows and OS X. Pfft! VIM. VIM is not the standard editor. There is only one standard editor, ed. That's why it's called an EDitor, not a VIMitor. Pfft. Only for people who can't handle using the Real One True Editor: TECO. http://en.wikipedia.org/wiki/TECO_(text_editor) steve Although I admit back in my MSDOS days I found a copy of ED which was ported there since it was at least infinitely better than EDLIN. And to be fair, VIM grew out of the classic vi which itself grew directly out of ed, so there's a little ed hiding in VIM trying to escape. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Value Error
or if you try to take the square root of a negative number, etc. On 12-Jun-2013, at 14:06, Sander Sweers sander.swe...@gmail.com wrote: On 06/12/2013 10:49 PM, Jim Mooney wrote: Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexErrorhttp://docs.python.org/2/library/exceptions.html#exceptions.IndexError You get this when the function gets the right object but the value of that object is not correct. For example int() will attempt to create an integer object from a string object. However if that string is not a number represented as a sting you run into a ValueError. int('test') Traceback (most recent call last): File pyshell#0, line 1, in module int('test') ValueError: invalid literal for int() with base 10: 'test' When we give it the string representation of 123 int() will convert the string to an integer. int('123') 123 ~Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Value Error
int('blah') is not a type error because the int() function is expecting to be given a string, and it was given a string. The 'blah' is of the correct type. The problem is that int() couldn't do anything useful with the value of that string. Steve On 12-Jun-2013, at 14:41, Jim Mooney cybervigila...@gmail.com wrote: Dave Angel da...@davea.name import math print math.sqrt(-1) Ah, that's what I was looking for. I already saw it trip on type mismatches like int('blah'). I was looking for what would be an actual inappropriate value that was still the right type. Although I'm not sure why int('blah') wouldn't be a type error rather than a value error. Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why can you swap an immutable tuple?
On 2013-5月-25, at 上午11:56, Jim Mooney wrote: I thought tuples were immutable but it seems you can swap them, so I'm confused: a,b = 5,8 I think you're confusing mutating the tuples with assigning the immutable tuples different names. The variable names are just labels you attach to them. The tuple values themselves cannot change. That said, your example here isn't a tuple but a pair of singleton values. If you said tuple1 = 1,2,3,4 tuple2 = 5,6,7,8 you create two tuples which are, yes, immutable. They happen to be called tuple1 and tuple2 but that's beside the point of immutability. If you pass them to a function, they'll be known locally there under different names but they're still immutable tuples. Does that help? --steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On Mon, Feb 18, 2013 at 07:01:02PM +, Matthew Ngaha wrote: understanding of how everything works. Use it., Experiment with it. Break it. Thats the best way. Read the source code its all available in Python or C. Hey can you please tell me which source code youre referring too? The initial files that come with Python? also the C code, where can i locate this? is C something worth learning? why is Python code available in C? C is definitely worth learning. So is LISP. And a handful of other languages we could enumerate. It's worth learning if it adds something useful to your understanding of how computers operate on the instructions you give them, or if it changes your approach to creating software in a fundamental way. Actually using those languages in daily life is not the point. C, however, is still very useful in a number of situations. Python programmers can get leverage from its strengths by--for example--writing performance-critical modules in C and then calling them from their Python programs. Python itself (well, the standard implementation of it anyway) is written in C. It has to be written in something that ultimately compiles down to the machine language which the computer actually uses. That C code interprets your Python code so you have a much nicer, high-level programming environment to work with. But the computer itself doesn't directly understand Python. yes i will try not to reinvent the wheel, a lot of tutorials ive read seem to always point this out. Just out of curiousity what is a bag, stack or circular list? what is needed to create something like this? i sort of heard about a stack its a C/C++ thing i think? None of these are C/C++ things. They are basic building-blocks of Computer Science and data structures you'll use regardless of language. I'd really recommend investing some time reading up on these and other fundamental data structures. -- Steve Willoughby| Using billion-dollar satellites st...@alchemy.com | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] if/else option for making a choice
On Mon, Feb 18, 2013 at 07:22:54PM +0100, Niclas Rautenhaus wrote: Hello folks, I hope it is clear where my problem is. Not completely, but let's take a look at what you have so far. # Set variables for additional items Leather = (500) int (Leather) Clima = (1500) int (Clima) ... You don't need to put parens around the values, but more importantly note that the int lines don't do anything here. When you say: Hifi = (250) int (Hifi) You set Hifi to the value 250 in the first line, which is fine, but then you call int() to turn the integer 250 into the integer 250, and then promptly discard that value. If you had, for example, a string 250 and wanted to turn it into an integer, you could do something like Hifi = int(250) But simply saying int(250) accomplishes nothing. Do you see why? print \n\nPlease enter the basic price: basic = int (raw_input()) I'm curious why the price of the car has to be an integer. Couldn't it be something like 15999.95? # Tax is a percentage of the basic car price Tax = basic * 5 / 100 You would be better off using floats here if you want a real number as the answer. You're working in integers. int (Tax) Or maybe you really want integers only to keep the numbers easier or something. Fair enough, but again this line does absolutely nothing. You truncate Tax to an integer but then discard that integer value as soon as it's created. print \nAdded items: # Here the user should have the possibility to pick either yes or no print \n\nLeather,(Leather) The parentheses are unnecessary here. To have them choose, you need some kind of if statement. Maybe something like choice = raw_input(Would you like windows?) if choice == 'yes': windows = 150 There are certainly more sophisticated ways to do this as well, when you get past the basics of how conditionals (if statements) work. For example, making a function that asks each question and handles all the different ways the user might answer other than typing precisely yes. Or putting the choices in a list instead of repeating the choice-asking code over and over. -- Steve Willoughby| Using billion-dollar satellites st...@alchemy.com | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Question
On 2013-1月-7, at 下午3:31, Dylan Kaufman wrote: Greetings, I take Computer Science in school and for a Python program, I have: from winsound import Beep The first thing I notice is from winsound import … Could that be a WINDOWS library which might not work on a Macintosh? Beep(196, 1500)#G Beep(262, 270)#C Beep(196, 200)#G Traceback (most recent call last): File /Volumes/PICKLES/School/MyClass/Comp. Sci/Chapter 02 Stuff/program2_cep.py, line 5, in module from winsound import Beep ImportError: No module named 'winsound' Looking at this, /Volumes/PICKLES/School/... that looks like a Mac filesystem mount point name to me. Looks like you're using something that works on Windows at school, then trying to use it on a non-Windows system at home. Try looking for a sound library which works on all platforms. Failing that, look for something that works on a mac. As a side note, you probably want to replace all those Beep() calls with some code which reads in a set of note values as data. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] optparse.OptionParser options in alphabetical order in help display
Although it is probably too obvious to be the answer you're looking for, why can't you just add them in order in the source code? This way, you can arrange them however you want them to appear, instead of python arbitrarily enforcing its own order. Python likes being explicit about things like that. rail shafigulin rail.shafigu...@gmail.com wrote: Does anybody know if there is a way to make --help option to display options in alphabetical order? Right now it displays options in the order I added them. I'm using Python 3.1 Any help is appreciated. Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Sent from my Android phone with K-9 Mail. Please excuse my brevity.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Hi, I am trying to write a programme to count how many times a random point lies within the positive sector of a circle. So far I can display if the point lies inside the area but I need something to allow me to count the total number of items that lie inside the area. My programme is: import random for i in range(10): x = random.random() y = random.random() count = 0 if x*x + y*y 1: count = count + 1 print count and I get a list down the screen like1 depending on how many times a random point lies in the area. I am meant to do this with 1 points so I can't simply count the 1's up like I can with 10. I have been looking on the internet but cant find anything that works yet. Thanks for your timeSteve Clarke ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help me decide
On 05-Sep-12 10:40, Alan Gauld wrote: On 05/09/12 11:04, Matthew Ngaha wrote: also please could you tell me why you suggest wxPython over GTK? Support, there are probably more beginner friendly resources for wxPython than for GTk, although that is changing. Yeah, and wxPython is a large, comprehensive package that should handle all of your GUI needs and then some. I wrote one tool using wxPython and was quite happy with the results, and pleasantly surprised at the performance of widget updates and refreshes it achieved, even for the bits in pure Python. that wxPython is the easiet to pick up yet a lot more complete than Tkinter? Not sure about that. I started Tk programming back (way back) in my Tcl/Tk phase years ago, so I'm really used to Tk and that may bias me, but I'd say Tkinter is a lot easier to learn than wxPython, partly because it's smaller with fewer moving parts to tweak. And yet, Tkinter is complete enough to be quite satisfactory for a lot of applications. Even after using wx, I've gone back to Tkinter when it sufficed for my applications, since it's a little easier to use and is a lot easier to distribute, coming for free with Python and all that. this has interested me. is embedded programming a different field to the type of programming in Python? Yes, it is usually done using assembler and C or C++. Some embedded work nowadays is done in Java - a reflection of how cheap memory has become! Right. Although Java here doesn't necessarily mean the JVM is running on the embedded machine; it could be Java source code compiled down to something a compact runtime can execute. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] understanding pydoc try
On 30-Aug-12 08:22, Dave Angel wrote: On 08/30/2012 10:43 AM, John Maclean wrote: On 08/30/2012 03:05 PM, Dave Angel wrote: snip Thanks. This is a heck of a lot more clearer to me! BNF, huh? Another set TLA that I don't need to know ;-) I learned BNF in about 1972. I've used about 35 languages since (not counting hobby ones). It can clarify a new language better than many paragraphs of description. But I've found that it's seldom completely rigorous. True, usually because people aren't as careful writing it as they are real code that needs to be executed by something. Maybe it would help to start by describing your grammar to YACC, getting it to work, and then expressing that back out as BNF (or just leaving it in YACC code). -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recursion always returns None
On 28-Aug-12 04:23, Dharmit Shah wrote: Hello, I am trying to do the following : 1) Ask user for the length of the word that he'd like to guess (for hangman game). 2) Pick a random word from /usr/share/dict/words (which I understand is not the best choice for hangman). 3) Call a function that would pick a random word to proceed further. Below is the code for the part I described above : I'm struggling to understand why you're using recursion here. It serves no evident purpose for what you're doing, and given a large dictionary of words, could seriously tank the performance of the application, quite possibly run it out of resources and crash it altogether. But since you're using recursion, note that when you make your recursive call, you're ignoring the return value from that call, so no returned value ever gets propagated out to the outer layers of recursion. If the outermost layer took the recursion (length of the chosen word is wrong), it calls itself and then never takes the branch including the return statement at all. (return word is never executed in that case). This causes the function to just 'fall off' the end which implicitly returns None. HTH [code] #!/bin/env python import random def pick_random(l, ln): # picks a random word from the list l of length ln global mystery word = random.choice(l) if word.__len__() != ln: pick_random(l, ln)# recursion else: print Should return %s % word # prints the chosen random word correctly return word # always return None, why? :( if __name__ == __main__: ln = raw_input(How long word can you guess (number of alphabets) : ) ln = int(ln) l = [] with open(/usr/share/dict/words, r) as f: for i in f.readlines(): i = i.split(\n)[0] if i.isalpha(): l.append(i) word = pick_random(l, ln) print word [/code] Sample output : $ python hangman.py How long word can you guess (number of alphabets) : 6 Should return inarch None $ The problem is that the last line print word always prints None. I know I am doing something wrong in the recursion part of the function pick_random. Can someone please point what I am missing. Thank you! Cheers, Dharmit -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recursion always returns None
On 28-Aug-12 09:03, Mark Lawrence wrote: On 28/08/2012 16:51, Dharmit Shah wrote: @ Steve : Thank you. As suggested by Dave Angel, I am going to try the loop. And even before implementing it, I can feel that it's going to be more efficient than recursion. May I ask why you appear to be concerned with efficiency for a hangman game? Not the game per se, but if you're searching a file of thousands of words one at a time, randomly picking words and recursing if they're not what you intended, the hit--worst case--could be catastrophic. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recursion always returns None
On 28-Aug-12 09:13, Alan Gauld wrote: On 28/08/12 16:51, Dharmit Shah wrote: @Dave Angel : Thank you for the loop idea. It didn't strike me at all. For some reason some beginners seem to find recursion a natural pattern. There is a certain hey, you can do that? That's cool! factor when you first discover recursion. When it naturally applies to a problem, it's still a powerful thing, but yes, it's often misapplied by beginners. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] finally without try or except
On 30-Jul-12 10:52, Mark Lawrence wrote: On 30/07/2012 17:56, Tino Dai wrote: Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? Sorry I'm not completely sure what you're asking for but will this help http://docs.python.org/library/atexit.html ? I don't think that will cover the use cases the OP asked about. I suppose you could do something like try: main() finally: save_everything() But I think it would be better to re-think your design. Why must the final database commit (or whatever it is) happen at the end and not along the way? Are there critical subsets of the code you could protect more locally and save after they're done? Are you certain that the data you'll save will be accurate if the program crashed or was interrupted in the middle of something? I think the block above will do what you're asking for, but I'm not sure what you're asking for is what will help you best. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Concatenating Strings
On 28-May-12 19:00, Jeremy Duenas wrote: and the both printed the same output……so why would I want to use ‘+’ to add strings if there seems to be no reason too? Juxtaposing strings only works with constants, which may be convenient in some cases, but it won't work at all when concatenating other string values. a=hello b=world a+b# will yield helloworld but a b# is a syntax error Using + is arguably preferable when you have a choice to make, since it works in all cases, including constants. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] feedback on writing pipelines in python
On 21-Mar-12 11:03, Abhishek Pratap wrote: Hi Guys I am in the process of perl to python transition for good. I wanted to Why? Perl is still a perfectly good tool. Just not, IMHO, good for exactly the same things Python is good for. 1. stitch pipelines : I want python to act as a glue allowing me to run various linux shell based programs. If needed wait for a program to finish and then move on, logs if required Look at the subprocess standard library module. It offers a complete set of options for launching processes, piping their data aound, waiting for them, handling exceptions, and so forth. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] decimal precision in python
On 07-Feb-12 03:15, Steven D'Aprano wrote: Steve Willoughby wrote: If you need lots of precision, you might consider using the decimal class. It'll cost you speed vs. the native floating-point type but won't cause you round-off errors. I'm afraid that's not correct. Decimal is still subject to rounding errors. from decimal import Decimal x = 1/Decimal(3) # one third, as close as a Decimal can give x + x + x == 1 False Sorry, I guess I took it for granted that was understood. I was referring to round-off caused by binary representation of a number that by all appearances is a simple, rational, non-repeating decimal number expressed in base 10. In other words, when you're adding up financial figures, you'll get an accurate sum without mysterious rounding off, but of course certain fractions which don't have a straightforward way to represent as a decimal value, like 1/3, are going to be an issue. Good catch, though, it was better to point that out. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] decimal precision in python
On 06-Feb-12 07:25, Kapil Shukla wrote: i tried writing a small code to calculate option price using the binomial tree model. I compared my results with results of the same program in excel. There seems to be a minor difference due to decimal precision as excel is using 15 decimal precision and python (both 2.7 and 3.1) using 11. (at least that's what shown on shell) If you need lots of precision, you might consider using the decimal class. It'll cost you speed vs. the native floating-point type but won't cause you round-off errors. natively, Python uses IEEE double-precision math for all float objects. For a float value x, instead of just printing it, try this: print('{0:.30f}'.format(x)) can some one guide me whats the equivalent of using a double datatype on python and i can't use long() in 3.1 any more. Equivalent to what degree? Python's float class generally will get you where you need to go. Also the int type automatically extends to arbitrary-precision integer values so you don't need explicit long type anymore. (Unless I misunderstood your question there.) Please also suggest a free editor for python which can at least repeat previous command with a key stroke I use vim, which has that feature. I suspect any editor worth its salt does, or could be programmed to. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SEE THE QUESTION AT THE BOTTOM
On 03-Feb-12 21:38, Debashish Saha wrote: BUT I COULD NOT UNDERSTAND HOW THE COMMAND ELSE CAN WORK,THOUGH IT IS IN THE OUTSIDE OF THE FOR LOOP IN WHICH IF COMMAND LIES. The part that's confusing you is that it is not outside the for loop. It is PART of the for loop syntax. The loop construct used is: for variable in list: list body else: else body This means you run variable. through each element of list, executing list body once for each iteration, and a statement in that body may elect to break out of the loop prematurely. If nothing breaks out of the loop (i.e., you exit the loop because the list was exhausted), then and only then execute else body. It's a handy mechanism to handle the case where the for loop failed to find whatever it was searching for. Most other languages I've used don't have this, and you end up doing messier manual logic steps to accomplish the same thing. Tip: Please don't type a message IN ALL CAPITAL LETTERS; it gives the impression you are shouting at your audience. HTH, HAND -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error Checking/Defensive Programming
On 25-Jan-12 19:49, Devin Jeanpierre wrote: On Wed, Jan 25, 2012 at 10:36 PM, Michael Lewismjole...@gmail.com wrote: if number=0 or 0: As long as we're helping with this, I'll just add a comment about this conditional statement. First, if you string together two expressions with or between them, they must each be complete statements. number=0 makes sense, but what does 0 mean? You'd really write it as if number = 0 or number 0: However, that doesn't make sense because if number is something that can be compared with integers like 0, it will either be = 0 or 0, so the condition will always be true. If number contains something that doesn't make sense to compare like that, then it just won't work (i.e., it'll likely throw an exception). (usually :) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Weird Try..Except Error
On 25-Nov-11 04:42, nikunj.badja...@emc.com wrote: Hi All, Thanks for the info. I had Python27 and Python32 both installed togethar. In Windows the PATH env variable, I had set Python27 exe and lib path. But When I do C:\ Python [PressEnter] I get 2.7 But when I run C:\ script.py [PressEnter] The script is running with Python3.2 , thts weird because I have set my Path variable with Pytho27 exe and lib. Which was causing the problem. The problem is likely that when you installed Python 3.2, Windows associated the .py extension with the new 3.2 interpreter, PATH notwithstanding. steve -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question on List Comprehensions
On 21-Nov-11 23:49, Charles Becker wrote: Alan, Steve, future readers, After some re-reading and hacking I was able to discover the solution. Since I raised the question here it is : [['{0}'.format(x+1), x+1] for x in range(size)] Just to fill out some other refinements for your information, if you're not planning to do anything special with the string formatting in each list, you don't really need to call format() when all it's doing is just making a string representation of the data value. so '{0}'.format(x+1) could just be str(x+1) Resulting in: [[str(x+1), x+1] for x in range(size)] Also, if you didn't like the repeated x+1 in there, you could just change the range call to go from 1..size directly: [[str(x), x] for x in range(1,size+1)] -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character ?
Where did the string come from? It looks at first glance like you have two bytes for each character instead of the one you expect. Is this perhaps a Unicode string instead of ASCII? Sent from my iPad On 2011/11/20, at 10:28, dave selby dave6...@gmail.com wrote: Hi All, I have a long string which is an HTML file, I strip the HTML tags away and make a list with text = re.split('.*?', HTML) I then tried to search for a string with text.index(...) but it was not found, printing HTML to a terminal I get what I expect, a block of tags and text, I split the HTML and print text and I get loads of \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character. Any idea what is happening and how to get back to a list of ascii strings ? Cheers Dave -- Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character ?
On 20-Nov-11 12:04, Sarma Tangirala wrote: Would the html parser library in python be a better idea as opposed to using split? That way you have greater control over what is in the html. Absolutely. And it would handle improper HTML (like unmatched brackets) gracefully where the split will just do the wrong thing. On 20 Nov 2011 23:58, dave selby dave6...@gmail.com mailto:dave6...@gmail.com wrote: Hi All, I have a long string which is an HTML file, I strip the HTML tags away and make a list with text = re.split('.*?', HTML) I then tried to search for a string with text.index(...) but it was not found, printing HTML to a terminal I get what I expect, a block of tags and text, I split the HTML and print text and I get loads of \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character. Any idea what is happening and how to get back to a list of ascii strings ? Cheers Dave -- Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html ___ Tutor maillist - Tutor@python.org mailto:Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character ?
It's customary to copy the list with answers, so everyone can benefit who may run into the same issue, too. On 20-Nov-11 11:38, dave selby wrote: It came from some automated HTML generation app ... I just had the idea of looking at in with ghex every other character is \00 , thats mad. OK will try ans replace('\00', '') in the string before splitting Those bytes are there for a reason, it's not mad. It's using wide characters, possibly due to Unicode encoding. If there are special characters involved (multinational applications or whatever), you'll destroy them by killing the null bytes and won't handle the case of that high-order byte being something other than zero. Check out Python's Unicode handling, and character set encode/decode features for a robust way to translate the output you're getting. Cheers Dave On 20 November 2011 19:15, Steve Willoughbyst...@alchemy.com wrote: Where did the string come from? It looks at first glance like you have two bytes for each character instead of the one you expect. Is this perhaps a Unicode string instead of ASCII? Sent from my iPad On 2011/11/20, at 10:28, dave selbydave6...@gmail.com wrote: Hi All, I have a long string which is an HTML file, I strip the HTML tags away and make a list with text = re.split('.*?', HTML) I then tried to search for a string with text.index(...) but it was not found, printing HTML to a terminal I get what I expect, a block of tags and text, I split the HTML and print text and I get loads of \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character. Any idea what is happening and how to get back to a list of ascii strings ? Cheers Dave -- Please avoid sending me Word or PowerPoint attachments. See http://www.gnu.org/philosophy/no-word-attachments.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about GUI applications.
On 08-Nov-11 00:39, Alan Gauld wrote: On 08/11/11 04:30, Nathaniel Trujillo wrote: I just wrote the following GUI application. How do I get rid of the 7k in the upper left hand corner and how to I put other stuff there like say a picture of someone. Thanks for the help. If you are using Windows I don't think you can, due to a bug in the underlying Tk libraries. If you are using Linux/MacOS then there is a function to replace the control icon. I can't recall what it is, but its similar to the one used for setting the title text on the Window, one of the wm_x calls. But you might get a better response asking on the Tkinter mailing list... I have an app I'm developing and running successfully on Windows (as well as OSX and Linux). At least in this case it is able to replace the application icon in place of the default TK one. The code I use is: root = Tkinter.Tk() root.iconbitmap(default=ico_image_filename) (on Linux I use root.iconbitmap(bitmap='@'+xbm_filename)) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginning Python From Perl
On 08-Nov-11 14:14, Jihad Esmail wrote: Hi! I am new to this list so stick with me. I've recently taken interest in learning Python. I have already learned Perl. How should I go about learning Python from Perl? Please help. Thanks! I, too, was a long-standing Perl programmer before diving into Python. The most important thing, and I just can't stress this enough, is that you should seek to understand Python on its own terms first. Learn the idioms and best practices of Python. Perl and Python (and C and Ruby and Java and... and ...) each have their strengths, weaknesses, and their own way of approaching a problem. If you just try to frame a program as you would in Perl, and translate the code into Python straight across, you'll get really crappy Python code and have a miserable time doing it. Don't program in Perl in Python, in other words. (Substitute Perl and Python with arbitrary languages of your choice.) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question about GUI applications.
On 08-Nov-11 16:38, Alan Gauld wrote: I note it says this sets the bitmap for the iconified widget. That to me means the icon on the desktop, or in the Taskbar. Can you confirm that it also sets the icon at top left in the title bar? Yes, it changes the top left of the application window. To test, I made a G image and installed it. Here's a screenshot of the app window with and without that code. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C attachment: tk-icon.pngattachment: g-icon.png___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] beginner question
On 01-Nov-11 08:34, Mayo Adams wrote: When writing a simple for loop like so: for x in f where f is the name of a file object, how does Python know to interpret the variable x as a line of text, rather than,say, an individual character in the file? Does it automatically treat text files as sequences of lines? Every object defines what its behavior will be when asked to do something. In this case, file objects know that they are capable of iterating over a list of their contents by being used in a for x in f loop construct. The file object knows to respond to that by yielding up a line from the file for every iteration. You could, theoretically, write a variation of the file object class which iterated over characters, or logical blocks (records of some sort) within files, and so forth. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] login window using Tk
On 01-Nov-11 09:47, Chris Hare wrote: Questions: 1. Is this the best way of doing this or is there a better way? 2. How do I exit the main loop when the user has authenticated? Why stop the main loop and restart it? Typically you'd setup the app, and start the main loop running for the duration. Everything else is handled by the application's logic. For example, you'd display the login toplevel window, and when it's satisfied, it can trigger the functionality which creates (or displays the pre-created but hidden) application window and dismisses the login toplevel. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GNU Emacs and Python
On 01-Nov-11 13:19, Alexander Etter wrote: I like than .png image! It does appear vi biased though! Not quite, notice the initial steep climb. :) Yes, it's tongue-in-cheek, but feels about right, once you master vi (or emacs) you're able to be amazingly productive with complex operations involving text files. You think emacs is bad, though? Try TECO. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] GNU Emacs and Python
On 01-Nov-11 13:24, Steve Willoughby wrote: On 01-Nov-11 13:19, Alexander Etter wrote: I like than .png image! It does appear vi biased though! Not quite, notice the initial steep climb. :) Yes, it's tongue-in-cheek, Oops, my mistake. If the y axis is productivity and x is time using the tool, then yes, a bit vi-biased. And that makes the Visual Studio graph make more sense as well :) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] changing dictionary to lowercase
On 27-Oct-11 11:25, ADRIAN KELLY wrote: Hi all, is it possible to change a dictionary list to lowercase..without having to retype? e.g. definitions={Deprecated: No longer in use, Depreciation: fall in value of an asset} i have tried definitions=definitions.lower() lower() is not a dictionary method, it's a string method (i.e., dictionaries have no idea how to lowercase themselves, but strings do). So what you need to do is iterate over the list of dictionary members and re-create a new dictionary with lowercased versions of the strings (that's easier than changing the dictionary in-place, especially if you're lowercasing the keys, since keys are immutable--you'd have to delete the old one and re-store the data under the lowercased key anyway) There are several ways to do that, including loops and list comprehensions. Does that nudge you in the right direction? If you're still stuck, let us know. --steve -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string immutability
On Mon, Oct 24, 2011 at 01:04:20PM -0500, Johan Martinez wrote: Hi, I am struggling to understand Python string immutability. I am able to modify Python string object after initializing/assigning it a value. So how does immutability work? I am not following it. Sorry for really stupid question. Any help? No, you're actualy not. s = First print s First At this point, you have created a string object with the value First and put that into the variable s (which is glossing over a detail about how Python variables realy work, but that's another topic). s = Second print s Second Now you created a new string object with the value Second and stored THAT into s, replacing the original object, which is now lost. -- Steve Willoughby| Using billion-dollar satellites st...@alchemy.com | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string immutability
On 24-Oct-11 12:17, Johan Martinez wrote: Thanks for the replies everyone - Steve, Dave, Sander and Wayne. I realized my wrong understanding/interpretation after posting the message to the list, which usually happens most of the time with me! That happens to most of us all the time too :) Unfortunately, with the lag between posting to the list and mail getting out to everyone, you'll probably get several replies that all say the same thing--we're not piling up on you, it's just a bunch of people being helpful without seeing that someone already answered yet. Glad we could help. Looking more into how Python variables work unlocks a lot of potential for all sorts of data structure operations that other languages require pointers to do, but are a lot easier when essentially all variables are references to objects but with the details handled behind the scenes for you. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] password loop
On 23-Sep-11 15:56, ADRIAN KELLY wrote: Can anyone help me with the programme below; i hope you can see what i am trying to do, if i enter the wrong password the loop goes on forever and if i enter the right one nothing is printed... i am a newbieall comments welcome Remember that raw_input() is what actually asks you a question and stores your answer somewhere. You only ever ask the question one time in your code, then keep re-checking the same value over and over, without anything to ever change its value. In a case like this, it's helpful (especially if you're new to programming) to step through the instructions you've written for the computer, one at a time, and repeat to yourself what each step is accomplishing. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Confirmation if command worked
On 25-Aug-11 01:37, Christian Witts wrote: Good catch, it should be `if child.exitstatus != None and child.exitstatus == 0:` It's better form to say if child.exitstatus is not None instead of comparing for equality to None with the != operator. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] inserting degrees symbol in plot title
On 09-Aug-11 20:11, questions anon wrote: I am creating a number of plots of temperature in degrees celsius and I would like the title of the plot to have - C° UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 19: ordinal not in range(128) Putting the Unicode character in your program is one thing, but what library functions you pass that data to is a factor, too. Without knowing anything about matplotlib, my guess from the exception you quoted here is that the library is expecting ASCII characters below 128, so that function won't accept the special character. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to get the keys of a dict inside a dict. ValueError: too many values to unpack
On 08-Aug-11 02:20, Kayode Odeyemi wrote: Either way, once you have the list of the keys you want to display, print them out once as column headings My concern is how do I print them out as columns, since writer.writerows is currently lining them out as rows (\n) Is there a function available for me to do this or do I have to construct the column structure myself, possibly leveraging the tab character or just basically construct a while loop and append spaces to each keys found? I would suggest using the string format() method to lay out the columns as you want them. You could use tab, but if your data values vary much, you'll get inconsistent results (i.e., if one row's value goes past the next tab stop). You'll want to create your own for loop to iterate over the (possibly sorted) list of values, printing each row the way you want it. Thanks On Mon, Aug 8, 2011 at 9:41 AM, Steve Willoughby st...@alchemy.com mailto:st...@alchemy.com wrote: Either way, once you have the list of the keys you want to display, print them out once as column headings -- Odeyemi 'Kayode O. http://www.sinati.com. t: @charyorde -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to get the keys of a dict inside a dict. ValueError: too many values to unpack
On 07-Aug-11 08:37, Kayode Odeyemi wrote: Hello all, Please I need help figuring out this permutation. I have a dict like this: x = {'pk': 1L, 'model': 'trans', 'fields': {'updated': 2011, 'tel': 3456}, {'pk': 2L, 'model': 'trans2', 'fields': {'updated': 2011, 'tel': 34510}; First of all, that's not a dict. It's just a tuple of strings. so, when you say: #loop through and get the keys of each for k,v in x: You'll get one iteration, where k=the first string and v=the second. However, you ignore k and v in all the code that follows, so I'm really confused what you're trying to do here. keys = dict(x).keys() Now you try to create a dict out of a tuple of strings, which won't quite work as written but in principle would only have created a dictionary with the first string as the key, and the second as value, not nested dictionaries. The dict() constructor really expects to see a sequence of key/value pairs, so it's going to take your sequence x as a list of two such pairs, and then raise an exception because the strings are not key/value pairs. This would succeed if you said keys = dict((x,)).keys() perhaps, but it's still not at all what you're trying to accomplish. print keys Note that you are re-assigning the value of keys each time through the loop but printing its last value after the loop exits. Is that what you intended? You're expecting Python to take a string that looks like Python source code and know that you want it to be interpreted as source code. Instead of using string values, use actual Python syntax directly, like: x = { 'pk': 1L, 'model': 'trans', 'fields': { 'updated': 2011, 'tel': 3456 } } -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to get the keys of a dict inside a dict. ValueError: too many values to unpack
On 07-Aug-11 09:17, Steve Willoughby wrote: First of all, that's not a dict. It's just a tuple of strings. so, when you say: #loop through and get the keys of each for k,v in x: You'll get one iteration, where k=the first string and v=the second. However, you ignore k and v in all the code that follows, so I'm really confused what you're trying to do here. I just noticed I glossed over a key point, for that to work you'd need x to be a sequence of such tuples. As it stands there, you'll get an error because each element of x is a single string, so it can't pull two values out of each of them. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running Python in script vs. Idle
On 24-Jul-11 16:21, brandon w wrote: Then I try to run it from a script in Gnome-terminal and it does not run. I do not get output. I have to add print. to get any output like this: When you type a Python expression at the interactive prompt in IDLE or the python command-line interpreter, it will take the extra step of printing the value of that expression for you. That's not otherwise how Python works. Normally you have to use a print command (or print() function in Python 3.x) to actually see the output. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Basic question on spaces
On 19-Jul-11 20:39, Alexander Quest wrote: Hello; I'm a new student of Python using Python Programming for Absolute Beginners 3rd edition by Michael Dawson as my guide. This is a basic question regarding spaces. I'm not sure how to make it so spaces do not show up between variables and basic strings, particularly before commas and after dollar signs, as in the simple tipper program I have below. You don't want to use print with a comma-separated list of values, then. Your best bet would be the format string method, like this: print Okay, based on that bill, a 15% tip would be ${0}, and a 20% tip would be ${1}. .format(percent15, percent20) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
On 11-Jul-11 16:50, Edgar Almonte wrote: Thanks for the hints , what i want accomplish is sort the line by the same value in the column 2 and 3 i mean the line with the same value in the 2 get together with the line in the same value in column 3 What if the same value appears more than once? Does it matter which ones you match up? If so, how do you decide? -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
On 11-Jul-11 17:18, Edgar Almonte wrote: this is just one time thing and the value don't get repeat Then you could make a single loop over the input lines, building two dictionaries as you go: * one that maps column 2's value to the rest of that line's data * and one that does this for column 3's value. Now run through the column 2 data you saved, print that data row, then look up the value in the other dictionary and print that after it. On Mon, Jul 11, 2011 at 7:55 PM, Steve Willoughbyst...@alchemy.com wrote: On 11-Jul-11 16:50, Edgar Almonte wrote: Thanks for the hints , what i want accomplish is sort the line by the same value in the column 2 and 3 i mean the line with the same value in the 2 get together with the line in the same value in column 3 What if the same value appears more than once? Does it matter which ones you match up? If so, how do you decide? -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] problem reading script
On 01-Jul-11 10:56, Corey Richardson wrote: Excerpts from Alan Gauld's message of Fri Jul 01 13:03:40 -0400 2011: I use and love inconsolata[0], it's a great font for programming, and looks great as well (both on screen and off). I like inconsolata and Envy Code R, although just to be weird I tried using an old OCR font and kind of got to like that too. A little weird but the glyphs are certainly distinct :) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Weird tkFont behavior
On 17-Jun-11 14:18, Alan Gauld wrote: But I confess I've never used font tags (and didn't even know they existed). Neither did I until now. I had been playing with WxPython previously (which is still a great toolkit I'd recommend when it makes sense), but I've been getting happier to see the improvements to what you can do with just plain Tkinter since the last time I used it seriously. Tkinter and ttk do have the advantage of already being right there in the standard library. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Weird tkFont behavior
I'm probably just doing something stupid, but I can't spot the error. I hope someone here can see what I'm looking past, or knows of a known issue with these widgets. I'm writing a GUI app using ttk widgets in Tkinter, which includes text displayed in a regular text widget. Some text in the widget will be in Italics, some bold, some both, some regular. I assigned those font effects as tags for the text widget as you can see in the code below. However, when I run it, about 10% of the time, the text widget will come up with random fonts (e.g., bold italic instead of plain roman), even though I confirmed that it's using 'rm' as the tag when inserting the text into the widget. The initial setup code includes: f = Tkinter.Text(self, ...) f.tag_config('rm', font=tkFont.Font(family='Helvetica', size=10, weight=tkFont.NORMAL, slant-tkFont.ROMAN)) f.tag_config('bf', font=tkFont.Font(family=Helvetica', size=10, weight=tkFont.BOLD, slant=tkFont.ROMAN)) f.tag_config('it', font=tkFont.Font(family=Helvetica', size=10, weight=tkFont.NORMAL, slant=tkFont.ITALIC)) f.tag_config('bi', font=tkFont.Font(family=Helvetica', size=10, weight=tkFont.BOLD, slant=tkFont.ITALIC)) f.tag_config('ref', font=tkFont.Font(family=Helvetica', size=10, weight=tkFont.NORMAL, slant=tkFont.ITALIC), foreground='blue', underline=True) text is inserted simply by: f.insert(END, text, 'rm') and yet some of the time, even though the 'rm' tag is there, I get one of the other fonts I configured for the other tags. Do I need to keep other references to the tkFont objects somewhere else or something? -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Weird tkFont behavior
On 16-Jun-11 09:52, Steve Willoughby wrote: I'm probably just doing something stupid, but I can't spot the error. I hope someone here can see what I'm looking past, or knows of a known issue with these widgets. I think I solved it, actually.. as I was typing this up, I wondered in passing about this: of the other fonts I configured for the other tags. Do I need to keep other references to the tkFont objects somewhere else or something? and I think that was it. I recoded it so that I store the Font objects independently of the tag configuration call, in case they were getting destroyed accidentally somewhere (I know you have to do that with other Tk objects such as images), and now I can't get the app to fail. If interested, here's the new setup code: | f=Tkinter.Text(self, ...) | | self.font_tags = {} | for tag, weight, slant, others in ( |('rm', tkFont.NORMAL, tkFont.ROMAN, {}), |('bf', tkFont.BOLD, tkFont.ROMAN, {}), |('it', tkFont.NORMAL, tkFont.ITALIC, {}), |('bi', tkFont.BOLD, tkFont.ITALIC, {}), |('ref',tkFont.NORMAL, tkFont.ITALIC, {'foreground':'blue', 'underline':True}), | ): | self.font_tags[tag] = tkFont.Font(family='Helvetica', size=10, weight=weight, slant=slant) | f.tag_config(tag, font=self.font_tags[tag], **others) (Added | in the left column to hopefully get the text to indent right with some mail readers. That's not part of the code, of course.) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner puzzle with unpacking argv
On 16-Jun-11 10:10, Lisi wrote: 1 from sys import argv 2 3 script, user_name = argv I have tried every permutation of white space I could think of that might have looked like the original, but I always get the same error: That will work ONLY if argv has at least 2 values in it. Your source code is ok as far as it goes. Try running your script with two command line arguments and see what you get. (The first argument should be the name of your script, incidentally). If your script were named foo.py, then running the command: foo.py would give you the error you see because argv only has 1 thing in it and you're trying to retrieve two. If you ran it as: foo.py bar that should work, and script would be foo.py and user_name would be bar. You could check len(argv) first to see how many items you have before you try to get two values from it. For more sophisticated argument handling, you could look at the optparse or argparse modules (but that's beyond the beginner level--something to keep in mind for later). -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] trying to translate and ebcidic file
On 14-Jun-11 11:40, Prinn, Craig wrote: I am looking for a way to translate and ebcidic file to ascii. Is there a pre-existing library for this, or do I need to do this from scratch? If from scratch and ideas on where to start? Bear in mind that there's no 100% straight-across translation, because ASCII and EBCDIC each has characters that the other lacks. However, to translate the character codes they share in common, you could do something as simple as using the translation table functionality built in to the string class in Python, setting up a table to convert between one and the other. of course, if you are on a Unix-like system, there's already a command for that, to convert a file E from EBCDIC to a file A in ASCII: $ dd if=E of=A conv=ascii or the other way: $ dd if=A of=E conv=ebcdic -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Communicating Between Programs Using Raw Inputs
On 14-Jun-11 15:48, Steven D'Aprano wrote: Normally you would do this by redirecting standard input. What operating system are you using? In Linux, you would do something like: # run script foo.py taking input from the output of bar.py foo.py bar.py Actually, no, that will send the *source code* of bar.py as the input to foo.py. I think you mean: bar.py | foo.py which also should work in DOS as well (although less efficiently). However, I don't know if this will actually work for raw_input. It may not. Try it and see. It should. Perhaps a better way is to have your program accept a user name and password on the command line, and only prompt for them if not given. Then you can say: foo.py --user=fred --password=y8Mr3@hzi This is one way. Another would be to use the subprocess module in Python which will let one program invoke another program, and have a file-like object on which it can write data, which the child program will see as its standard input (and read in to raw_input). -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Communicating Between Programs Using Raw Inputs
As always, Alan has given a lot of great advice and useful information. There's just one piece at the end I would question, however: On 14-Jun-11 16:36, Alan Gauld wrote: python reader.py `python writer.py` Almost, but not quite. The backticks mean the command is executed and the output substituted back on the command line. The bracket means to take what follows it as a file NAME (not a data stream). So unless writer.py outputs a filename, you really want something like python writer.py | python reader.py -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Objects C++ vs Python
On 08-Jun-11 22:38, Ashwini Oruganti wrote: I'm trying to learn Python, and know C++. I have a slight confusion regarding the meaning of object in python. Here's what I've concluded so far: When we say object in C++, it means an instance of a class. e.g. This is true in both Python and C++. int x;// x is NOT an object, it is a *variable* You're confusing variables and the things they hold. x here is a variable which contains an int type value. Another variable might hold a pointer to an object. while in python, from what i've understood so far, x=5 implies that there's a memory allocation (called object) that holds the value 3, and x is the variable (or name) that is used to refer to it. Maybe this will be more clear: The value 5 is an integer-class object. Full stop. Don't even go down the road of thinking of memory allocation (yet). It's an object floating around in Python's runtime somewhere. x is a name you gave to that object for now, so you can refer to it somehow. The big difference is that variable names in Python are really just names for objects (something like pointers/references in C++ but a lot easier to work with), while in C++ they refer to specific memory locations, which must be the right size for what you store into them. Since Python is just naming objects, there is no such problem. That has nothing to do with what an object means. So does the term *Object * change its meaning when we shift the context from C++ to python?? This is a little confusing, can someone clear it up?? Not really. I think your confusion was about variables. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Objects C++ vs Python
On 08-Jun-11 23:33, Ashwini Oruganti wrote: On Thu, Jun 9, 2011 at 11:31 AM, Steve Willoughby st...@alchemy.com mailto:st...@alchemy.com wrote: The value 5 is an integer-class object. But now what is Integer-class? Isn't integer a data type? I mean there is no concept of classes in C, and yet in C, we can write In Python, everything is an object, so integers are objects. In C, integers are a fundamental data type. C doesn't have objects at all. Classes are data types, too, though, (the combination of a data representation and the set of behaviors that define what that data does in your program). int x = 5; Will 5, then be called an integer class object? In an object-oriented language, yes. In C, no, since it doesn't even have classes. What exactly is a class now? I thought is a collection of variables and (or) associated functions. Am I missing something here? But in an object oriented language such as Python, we have classes and objects, and integers are just another class of data objects. In this case, it's a very simple data structure with an associated set of methods to do things like add integers together, compare them with each other, etc. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] create an xls file using data from a txt file
Maybe we're splitting hairs over semantics then. I thought there was confusion about what the CLI shell was doing with file separators as opposed to just handing the arguments as-is to the applications (which is true... the CLI doesn't really process them much, it's up to the application. Where in the application, though, this is dealt with is not where I think we disagree. In my original response, I clarified that, although as a short parenthetical note: On 12-May-11 02:25, Peter Otten wrote: Steve Willoughby wrote: Actually, yes, that's exactly what Python (or actually the underlying file handling libraries it's built with) is doing on Windows. There is the underlying file handling libraries would be the API calls. But that's not the CLI shell's doing. Although maybe that's what you meant all along. There are enough difference between the way the Windows CLI shell and Unix-derived command shells function in the handling of files and option handling that there's often confusion there which I thought was what was happening here too, that the OP was saying the CLI was somehow doing the translation. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] create an xls file using data from a txt file
On 11-May-11 12:14, James Reynolds wrote: Actually, I never knew that about the windows separators, since I've just always used the '\' out of habit. If you want your code to run everywhere, you should use the functions in os.path to manipulate and build paths. Otherwise, using \ all the time means your code will ONLY ever work on Windows. Using / all the time means your code will work fine on Mac OS X, Linux, or other POSIX systems, and PROBABLY ok on Windows most of the time, but not on other systems. out path = 'C:\\test.xls', which will be 'C:\test.xls' or you can write out path = r'C:\test.xls' the r bit tells python that the following is a regular expression. or regex. Not to be too pedantic, but since this is a tutorial list, I'll point out the more accurate answer so new programmers don't get a mistaken impression. The 'r' string prefix does not actually mean regular expressions. It means raw string where (almost) no backslash codes are recognized in the string constant, so you could say r'C:\test.xls' instead of 'c:\\test.xls'. Raw strings are, however, really useful for strings which hold regular expressions, so you see them in that context a lot. ... ah... and I just noticed that this was pointed out later in the thread. Sorry for the repeat there. ‘/’ is perfectly valid Windows separator. See the *tested* examples below. It works just fine pretty much anywhere I have ever tried it, including the command line. (except apparently for an MSOffice file save dialog that I tried just now) Not... quite. / is accepted by a number of programs, including the Python interpreter, which came from Unix-like systems where / is the directory separator. Very old versions of MSDOS could be configured to use / on the command line for pretty much everything, but that has been deprecated for a long time now (they originally wanted / for command-line switches instead, so used \ for directory separators). Core windows commands don't generally accept it, including native Windows applications (although sometimes they're lenient in what they accept). It'll work for command-line Python script usage because it's *python* that allows them, not *windows*. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] create an xls file using data from a txt file
On 11-May-11 15:54, Prasad, Ramit wrote: Core windows commands don't generally accept it, including native Windows applications (although sometimes they're lenient in what they accept). It'll work for command-line Python script usage because it's *python* that allows them, not *windows*. They work in *Windows* command prompt natively. Respectfully, I think you aren't clear on how command line execution works. Hopefully I can help a little (yes, there are enough cases where it'll bite you that it's good to know this). Some apps do not work well that is true, but the reason that theywork like this with Python is NOT because Python allows it but because Windows does. I highly doubt Python checks for / and converts it to \\ (or does any complicated checking of file strings). YMMV for apps, but I have never had a problem with '/' on the command prompt. It is an important caveat to note that this behavior is not Guaranteed. Actually, yes, that's exactly what Python (or actually the underlying file handling libraries it's built with) is doing on Windows. There is a decades-long tradition of C compilers (et al) doing this conversion for the sake of all the ported Unix C programs that people wanted to run on Windows (or, at the time, MSDOS). If Windows natively supported it, then you could do this: C:\ DIR /users/fred/desktop C:\ DEL /temp/myfile Or try running your Python program like C:\ /python27/python.exe scriptname.py That doesn't work either, because Windows is NOT in any way at all interpreting the / characters. So why does this work: C:\ myscript.py /temp/myfile /users/fred/desktop or even C:\ \python27\python.exe myscript.py /temp/myfile That works because Windows hands ALL of the argument strings, as-is, with NO interpretation, to the application to deal with. In this case, the application is Python, and Python is going to the extra work to interpret the / characters as \ characters when you try to use them in open() calls and the like. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading elements in a file
On 04-May-11 11:40, Greg Christian wrote: Python version = 2.7.1 Platform = win32 I am kind of stuck on what is probably a simple thing: If we have a file of words like this: “first”,”word”,”in”,”that”,”another”,”part”,”of”,”this” It depends on exactly how just like that example the file is. For example, if it's a comma-separated value (CSV) file, with values enclosed optionally in quotes (as shown in your example), you can very easily and yet robustly read it using the csv module in the standard library. Otherwise you could use regular expressions to find text inside quotes and ignore the commas. Or split on ',' then strip quotes, or... CSV is easiest if that's a match for your problem domain. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Just started Python
On 27-Apr-11 14:35, Edgar Almonte wrote: try this : model=raw_input(What kind of car do you drive?) gallons=raw_input(How many gallons have you driven?) number1 = float (gallons) miles=raw_input(How many miles have you driven?) number2 = float (miles) try: number1 = float (gallons) number2 = float (miles) Indentation error aside, you'll never reach that exception because the previous number1 = float(gallons) would raise one if the input was wrong. Either move the try..except block to enclose the first one, or wait until the try...except block to do the typecast. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with running Python
On 22-Apr-11 07:13, Alex Butler wrote: Hello all, I am new to programming on Python and am teaching myself. I have figured Hi, Alex, welcome to programming and the Python language. If you want to get the most out of this list, it helps to ask very specific questions, showing what you have tried so far to figure out your problem, with what results. Including examples of your actual code and actual error messages is enormously helpful. out some basics of coding, however whenever I try to run the program or check its functionality (Alt + X on my windows) it always comes back saying that “there’s an error in your program: invalid syntax.” However, when it returns to the IDLE page and highlights the error, it highlights the 7 in the python 2.7.1 above any coding. And if I am able to delete that text, it then links the syntax error to the multiple ‘’ in the code. Is this a common issue with a simple fix? Thanks It sounds to me like you're confusing the actual program code with other stuff like the prompt Python's interpreter types to you. Are you cutting and pasting more into IDLE than the Python program code itself? You should not have things like Python 2.7.1 or showing up in your source code. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 22-Apr-11 15:37, Brad Desautels wrote: Hello, I am just learning Python 3.0 and I am working on this problem. I need to know what the output would be.Can anybody help What is your question? If you want to see what its output would be... run it and see the output. Is there more to your question, like what *should* the output be? (in which case, tell us what your output *is* and we can help you see why it's not what you expected). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 22-Apr-11 15:48, Brad Desautels wrote: Ya, I did try to run it and I am getting a syntax error before it runs. and the message said? Where did it point to as the syntax error? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python trouble
On 22-Apr-11 11:52, Alex Butler wrote: Ok let me try to be more clear. I am trying to write code in the IDLE Python GUI of python 2.7. When I open the new python shell, there is a written header as well as the three s on the left side. I now those are used as indents and I do not type them in. However, whenever I write any type of code and either attempt to run or click alt + x to check module, it says “there is an error in your program: invalid syntax.” Then when it goes back to the page to highlight the syntax error the second is highlighted in color as it is the problem. Before I deleted the header from this program, it would highlight the 7 after the 2. In the header. Okay, that's pretty much what you said last time. What is the actual code you're trying to run? If it's really complaining about being a syntax error, it sounds like you're confused about where you are in the tool or extra text is getting pasted. If you open a new source window (file-new) (not a shell window), and type some python code, that window won't have a header line or prompts at all, just your code. So... start IDLE select File-New; new untitled window pops up type a python program, maybe this: print hello hit alt-X (although personally, I'd hit F5 instead). It should prompt you for a file to save your new program into, then run it back in the other window (the shell) that has the s in it. How, exactly, does what I just described differ from what happened to you? -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
On 22-Apr-11 16:03, Brad Desautels wrote: Hi Steve, I am getting my error on main() I think it is possibly be an indentation error It should be easy to check. Make sure def main(): is all the way to the left, and all the lines under it are the same level as each other but usually indentation errors say that they are indentation errors. Look carefully at your parentheses. Does every ( have a matching )? -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
On 22-Apr-11 16:54, Frederick Grose wrote: With Bash, when one needs to halt the current root filesystem, to pivot to a new filesystem, one can copy some of the command files and their dependencies to a temporary file system and execute from that code base. I'm not sure those words mean what you think they mean, or I'm missing what you're trying to do here. halting the root filesystem? pivot? code base? You're not trying to talk about jail/chroot, perhaps? -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
On 22-Apr-11 17:14, Frederick Grose wrote: The particulars are that I've rebuilt a Fedora LiveOS filesystem image from a currently running instance (incorporating the filesystem changes in the device-mapper overlay into a new base filesystem image file). Right, so essentially you're talking about chrooting into the LiveOS image temporarily. It's not really halting as such, just where the OS's idea of root is at the moment. That involves mounting your LiveOS filesystem as well. The short answer is that if you can do it in the shell, you can do it in Python, but there's got to be more to the story than just this. What are you trying to actually do that you need Python for this? I assume you're trying to automate the process of what you're doing? Almost probably this is possible with Python, if I understand what you're doing. If you just want to know how to write a Python script around the steps you want to accomplish, as a simple beginning Python experience, we may still be of service to you. We could, for example point you to read up on the os.chroot() function in the Python standard library. If your question has more to do with the particulars of managing chroot()ed mountpoints or preparing LiveOS images, you'd need to look to a forum devoted to that. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] working with strings in python3
On 19-Apr-11 06:44, Rance Hall wrote: On Mon, Apr 18, 2011 at 9:50 PM, Marc Tompkinsmarc.tompk...@gmail.com wrote: On Mon, Apr 18, 2011 at 6:53 PM, Rance Hallran...@gmail.com wrote: I think you misunderstood me, I simply meant that the print .join(message) has to parse through each word in order to get any output, I didn't mean to suggest that you got output one word at a time. Sorry for the confusion. Not quite true. join() doesn't need to parse through words or anything. It takes a list of strings and efficiently copies them into a new large string. Maybe you're thinking of split() or something? I'm not sure I buy this explanation as strings have been used as keys in dictionaries or associative arrays for a long time, a string variable is variable or mutable, where a keyname can not be. You're forgetting that you're not talking about a string VALUE like in most other languages, but rather a string OBJECT. In C, if you store a value in a hash table with a string key, that key doesn't change even if the variable it came from takes a new value. So it doesn't upset the key at all. In Python, the string OBJECT you use may still be referenced by a variable, so if you were to mutate that string object, it would change and ALL variables referring to it would see the change, including the hash table structure which forms the dictionary. In this sense, think of Python variable names more like C's pointers (sort of). It's the same effect you'd get if you kept a pointer (in C) to the string value you stored your data in a hash table there, then went through that pointer to corrupt the hash table after the fact. I'm not sure if your background in programming includes those concepts (I'm assuming so) or if I explained that clearly enough, but that illustrates why Python string OBJECTS need to be immutable (as are simple numeric OBJECTS. The confusion that trips a lot of new Python programmers is that Python variables don't work like other languages, they're more of a blending of variables, pointers and references which just do the right thing most of the time due to how Python manages variable access. But they are not quite the same as any of those in other languages. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] adding to PYTHONPATH
On 19-Apr-11 06:49, mes...@juno.com wrote: How can I add a directory to PYTHONPATH? Using Ubuntu 10.04. That's an environment variable, so it depends on your shell. If PYTHONPATH already exists, you can add your directory to it (with colons between the names of directories). But you probably want this to be a permanent change, so you need to edit the start-up file for your shell (.cshrc, .bashrc, .profile, whatever) and add an instruction to set that variable everytime you open a shell. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] working with strings in python3
On 18-Apr-11 17:17, Rance Hall wrote: if test: message = message + Humbug! I'm sure this is not the way we are supposed to augment strings like this. maybe there is string.append() method or something I should be using instead? Nope, strings are immutable so once they are instantiated they cannot be changed (or lots of things like dictionary keys would break). So you want to create a new string value by taking the current value of message, plus a new value, and assigning that back to the name message as a new string object: message = message + Humbug! Although that can be more conveniently written as message += Humbug! There are other approaches, like building a list of strings and later joining them, etc., but that depends on your application as to what approach makes most sense for you. message.append() is impossible because that would be altering the string object named by message in-place, which is disallowed for strings. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.chdir() will not accept string variable
On 15-Apr-11 18:00, Rodney Lewis wrote: I cannot get os.chdir() to accept inputData[0]. os.chdir() works as expected in the interpreter when I put the little 'r' before the exact same string but as a literal, e.g.: rF:\Music\Siouxsie and the Banshees\the rapture It's because the string in inputData[0] has a trailing newline. WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect 'F:\\Music\\Siouxsie and the Banshees\\the rapture\n' Why is it doubling the backslashes and adding '\n' to the end? How do The actual string value is: F:\Music\Sousie and the Banshees\the rapturenewline When printing it out to you in the error message, Python REPRESENTED that string TO YOU with extra backslash codes so you could see what was in the sring: F:\\Music\\Sousie and the Banshees\\the rapture\n The extra backslashes aren't really in the string. Your problem is that readlines() retains the end-of-line character in the lines it reads, which is not actually part of the filename, so os.chdir() doesn't like it. You'll need to strip off the newlines from the strings you read before giving them to os.chdir(). I make it stop? What does the little 'r' mean before a string literal and how do I do the same for a string variable? It means not to interpret (most) backslash codes in the string as it's compiled from your source code into the internal string data managed by the program. If you wanted to put that string literally in your source code, you could do either of these: 'F:\\Music\\Sousie and the Banshees\\the rapture' or r'F:\Music\Sousie and the Banshees\the rapture' But that's not your problem in this case. You don't need this when reading in lines of data from another source, since they wouldn't get the same backslash interpretation as source lines do. # mdf -- mp3datafixer import glob, os def mdf(): inputFile = open( 'mdfinputs.txt', 'r' ) inputData = inputFile.readlines() inputFile.close() os.chdir( r'%s' % inputData[0] ) newNames = [] oldNames = glob.glob( '*.*' ) for index, item in enumerate( oldNames ): print index, item if __name__ == '__main__': mdf() raw_input( \nPress 'enter' to close console window: ) # Keeps console window open in Windows Thanks! -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] RE
On 06-Apr-11 02:03, JOHN KELLY wrote: I need help. Can you be a little more specific? :) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Platform Independence in Python
On 06-Apr-11 21:39, Ranjith Kumar wrote: On Thu, Apr 7, 2011 at 10:04 AM, Ratna Banjara mast.ra...@gmail.com mailto:mast.ra...@gmail.com wrote: In windows we should write =import tkinter while in linux, we should write =import Tkinter Actually, you should do the same thing on both platforms. Are you running the same code on both platforms? The correct name is Tkinter (capital T) for Python 2.x, and tkinter (lower-case) for Python 3.x, regardless of platform. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String formatting question.
On 31-Mar-11 09:46, bob gailer wrote: IMHO % formatting is the easiest to use and understand. I am sorry that it has been slated for removal. I had the same reaction, but I think it was mostly because of my long background as a C programmer, since it's essentially the equivalent of printf() formatting. Just heavily ingrained in my brain. However, since the more recent Python 2 versions have supported str.format(), and anticipating their removal from Python 3, I have started gravitating more to them, and I have to admit they're more powerful and probably a good evolutionary step to take. Especially so if your formats are configurable or generated by code which may want to reorder the values. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Regex question
On 29-Mar-11 23:55, Alan Gauld wrote: Andrés Chandía and...@chandia.net wrote in perl there is a way to reference previous registers, $text =~ s/u(l|L|n|N)\/u/$1e/g; I'm looking for the way to do it in python If you're using just a straight call to re.sub(), it works like this: text = re.sub(r'u(l|L|n|N)/u', '\1e', text) You use \1, \2, etc. for backreferences just like all the other regex-based editors do (Perl's more of an exception than the rule there). Alternatively, you can pre-compile the regular expression into an object: pattern = re.compile(r'u(l|L|n|N)/u') and then substitute by calling its sub() method: text = pattern.sub('\1e', text) -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Regex question
On 30-Mar-11 08:21, Andrés Chandía wrote: Thanks Kushal and Steve. I think it works,a I say I think because at the results I got a strange character instead of the letter that should appear this is my regexp: contents = re.sub(r'(u|span style=text-decoration: underline;)(l|L|n|N|t|T)(/span|/u)', '\2\'' ,contents) Remember that \2 in a string means the ASCII character with the code 002. You need to escape this with an extra backslash: '\\2\'' Although it would be more convenient to switch to double quotes to make the inclusion of the literal single quote easier: \\2' How does that work? As the string is being built, the \\ is interpreted as a literal backslash, so the actual characters in the string's value end up being: \2' THAT is what is then passed into the sub() function, where \2 means to replace the second match. This can be yet simpler by using raw strings: r\2' Since in raw strings, backslashes do almost nothing special at all, so you don't need to double them. I should have thought of that when sending my original answer to your question. Sorry I overlooked it. --steve -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] accessing another system's environment
On 26-Feb-11 01:19, ALAN GAULD wrote: Bill, That's the same thing we are talking about. The problem is those environment variables are highly variable so you can't talk about a machine's environment. Two users on the same machine (at the same time) may have very different environments. And a batch file or program can I'm a Unix hacker, so forgive me if my understanding of Windows is a bit naive. I think, though, that Windows has a set of environment variables which are system-wide, added automatically to the user set of variables when a new process is launched. Yes, they can be changed or deleted but there is a standard set applied to all users. If that's a correct assumption on my part, there must be somewhere that can be read from, probably (I would guess) in the registry. So a script which could read/write those registry keys may do what is required here. The issue of exposing that to remote machines remains a dangling issue, though. Of course, it's not entirely clear we're solving a Python question, although this discussion may well go more solidly into that space. add or remove variables too. So when I run python2 I may have the PYTHONPATH seet to one thing, but if I run python3 I have it set to something different. And I could be running both at the same time. And another user (or service) logged into the same machine might be running a Django web server with yet another setting. So what is PYTHONPATH for that machine? The USER and HOME Values are set by the OS to different values depending on who is logged in, but the user can then change these later, etc... Even with no users logged in you might have different services running each with their own environment set up. It is very difficult for an admin to do anything reliably based on environment variable settings. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ http://www.alan-g.me.uk *From:* Bill Allen walle...@gmail.com *To:* Alan Gauld alan.ga...@btinternet.com *Cc:* tutor@python.org *Sent:* Saturday, 26 February, 2011 2:50:39 *Subject:* Re: [Tutor] accessing another system's environment I apologize for not have been clear previously. What I am trying to access are the Windows system environment variables. The same ones that are listed out if you type the set command at a command prompt in Windows. --Bill On Fri, Feb 25, 2011 at 03:11, Alan Gauld alan.ga...@btinternet.com mailto:alan.ga...@btinternet.com wrote: Bill Allen walle...@gmail.com mailto:walle...@gmail.com wrote I have times when it is useful for me to check the environment of a user system on our lan remotely while trouble shooting and issue with them. Now, this is quite easy to do while I am using a windows system via the computer management console. I think we are meaning different things by environment? Can you give a specific example? However, I am trying to do this via a linux workstation (which is joined to the domain, etc.). I cannot find a native facility to duplicate the computer management functions, so I thought I would write a program to fill the need. Anything you can do locally you can do on the remote machine with a combination of ssh, rsh, rlogin, telnet etc. ssh is the safest but requires a bit more admin to set it up properly for maximum convenience. Having got remote access its just a case of figuring out which of the 500 or so Unix commands you need to use to do the job... :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org mailto:Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] accessing another system's environment
On 25-Feb-11 18:50, Bill Allen wrote: I apologize for not have been clear previously. What I am trying to access are the Windows system environment variables. The same ones that are listed out if you type the set command at a command prompt in Windows. There isn't a system set of environment variables on Unix-like systems--there is a default starting set per user (although they are configurable per-process as has already been stated). Perhaps you want to see the set of variables for the root account? But again, I have to ask what you're really trying to accomplish. Environment variables are only such a small part of a system's configuration, on Windows or Unix/Linux. On a Windows box, I would probably be more interested in what's in the system registry, for example, and on a Unix system I'd want to see what's in various configuration files in /etc to know what's configured on that system. Environment variables, from the point of view of a random process running on the system, are pretty much the same on both Windows and Unix. Where they come from, and which are system or user variables, is quite different, and I suspect you're reaching for environment variables out of habit but that may not ultimately be what you're really looking for here. Or maybe it is. If it is, step back and consider WHOSE set of variables you really want? The root account? the account of a service that you're interested in? The default skeleton configuration files for new users? The environment of something you know to be running already? All of those things are possible to look at, if you know what you're really after and why it will help you accomplish what you need to do. --steve --Bill On Fri, Feb 25, 2011 at 03:11, Alan Gauld alan.ga...@btinternet.com mailto:alan.ga...@btinternet.com wrote: Bill Allen walle...@gmail.com mailto:walle...@gmail.com wrote I have times when it is useful for me to check the environment of a user system on our lan remotely while trouble shooting and issue with them. Now, this is quite easy to do while I am using a windows system via the computer management console. I think we are meaning different things by environment? Can you give a specific example? However, I am trying to do this via a linux workstation (which is joined to the domain, etc.). I cannot find a native facility to duplicate the computer management functions, so I thought I would write a program to fill the need. Anything you can do locally you can do on the remote machine with a combination of ssh, rsh, rlogin, telnet etc. ssh is the safest but requires a bit more admin to set it up properly for maximum convenience. Having got remote access its just a case of figuring out which of the 500 or so Unix commands you need to use to do the job... :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org mailto:Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] accessing another system's environment
On 25-Feb-11 19:27, Steve Willoughby wrote: Wait. Are you trying to figure out how, on a Unix system, to read Unix system environment variables as you're accustomed to doing on Windows? Or are you saying you want to, from a remote Unix system, reach out to a Windows system and see that Windows system's system environment variables? On 25-Feb-11 18:50, Bill Allen wrote: I apologize for not have been clear previously. What I am trying to access are the Windows system environment variables. The same ones that are listed out if you type the set command at a command prompt in Windows. There isn't a system set of environment variables on Unix-like systems--there is a default starting set per user (although they are configurable per-process as has already been stated). Perhaps you want to see the set of variables for the root account? But again, I have to ask what you're really trying to accomplish. Environment variables are only such a small part of a system's configuration, on Windows or Unix/Linux. On a Windows box, I would probably be more interested in what's in the system registry, for example, and on a Unix system I'd want to see what's in various configuration files in /etc to know what's configured on that system. Environment variables, from the point of view of a random process running on the system, are pretty much the same on both Windows and Unix. Where they come from, and which are system or user variables, is quite different, and I suspect you're reaching for environment variables out of habit but that may not ultimately be what you're really looking for here. Or maybe it is. If it is, step back and consider WHOSE set of variables you really want? The root account? the account of a service that you're interested in? The default skeleton configuration files for new users? The environment of something you know to be running already? All of those things are possible to look at, if you know what you're really after and why it will help you accomplish what you need to do. --steve --Bill On Fri, Feb 25, 2011 at 03:11, Alan Gauld alan.ga...@btinternet.com mailto:alan.ga...@btinternet.com wrote: Bill Allen walle...@gmail.com mailto:walle...@gmail.com wrote I have times when it is useful for me to check the environment of a user system on our lan remotely while trouble shooting and issue with them. Now, this is quite easy to do while I am using a windows system via the computer management console. I think we are meaning different things by environment? Can you give a specific example? However, I am trying to do this via a linux workstation (which is joined to the domain, etc.). I cannot find a native facility to duplicate the computer management functions, so I thought I would write a program to fill the need. Anything you can do locally you can do on the remote machine with a combination of ssh, rsh, rlogin, telnet etc. ssh is the safest but requires a bit more admin to set it up properly for maximum convenience. Having got remote access its just a case of figuring out which of the 500 or so Unix commands you need to use to do the job... :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org mailto:Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] accessing another system's environment
On 25-Feb-11 20:26, Bill Allen wrote: On Fri, Feb 25, 2011 at 21:33, Steve Willoughby st...@alchemy.com mailto:st...@alchemy.com wrote: On 25-Feb-11 19:27, Steve Willoughby wrote: Or are you saying you want to, from a remote Unix system, reach out to a Windows system and see that Windows system's system environment variables? Yes, that's it exactly.:-) Ok... this is starting to make more sense then. So you have two problems, really. One is to get the linux box to invoke a command remotely on the windows box, and the other is what command to run on the windows side. Either *could* be a Python script, in theory, but those are two separate problems. There are lots of ways to go about this. You could write some kind of service in Python (CPython, or IronPython/.net or even C# or whatever) which manages the settings on your windows system. A Python script could then be written to interact with that service. Or, you could use a linux RDP-compatible tool to interactively run commands on the windows box for you. One question you need to figure out is how interactive you want this to be, or how automated. That will drive the implementation of what comes after. As will the list of available options at your site for securely allowing a remote host to run administrative tools on your windows systems. I administrate the workstations in our engineering environment and some of the major pieces of software we use are configured via the Windows system environment variables. Being able to reach out to a PC and check or change those is handy, even important, in my situation. I am trying to explore the possibility of managing these from a system I am using in a platform independent way and figure that I ought to be able to do this with Python. Perhaps there are third party Python modules I need to help accomplish this? --Bill -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python object
On 24-Feb-11 08:13, James Reynolds wrote: I don't understand what you are trying to do? I'm assuming def GetAllAtrib is a method within a class; perhaps you could copy more the code base? It seems to be locating the three elements you have in that method just fine, but I'm guessing you have another print statement somewhere that is causing it to print None. Or perhaps calling the method from an IDE or interactive prompt, where the print statements in the method are printing as intended, but the interactive environment itself is printing the return value from the method? This could happen if you did this at the prompt: print object.GetAllAtrib() This is a case where giving us more information about what you're doing helps us answer your question better. --steve On Thu, Feb 24, 2011 at 10:48 AM, Christopher Brookes chris.klai...@gmail.com mailto:chris.klai...@gmail.com wrote: Hi, i'm new in python. I'm trying to create a small fight program in object. I've created __init__ (its works) but when i'm trying to display init param i'm getting param and None every time. Why ? def GetAllAtrib(self): print '---' print self.name http://self.name print self.description print self.type print '---' give - --- Klaitos Soldier very strong Soldier --- *None *-- WHY ARE U HERE ?? Yours, -- Brookes Christopher. ___ Tutor maillist - Tutor@python.org mailto:Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 48A3 2621 E72C 31D9 2928 2E8F 6506 DB29 54F7 0F53 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor