Re: [Tutor] Puzzled again

2011-08-02 Thread Dave Angel
On 08/02/2011 10:36 PM, Richard D. Moores wrote: Puzzled again. Why the error. Line 36 is the line just above "import os.path". I have many other functions in mycalc.py with examples formatted exactly the same way. def convertPath(path): """ Given a path with backslashes, return that p

Re: [Tutor] Puzzled again

2011-08-03 Thread Dave Angel
On 08/03/2011 02:07 AM, Richard D. Moores wrote: On Tue, Aug 2, 2011 at 21:59, Dave Angel wrote: When I paste that from your email into a file and run Python 2.7 on it, it behaves fine with no errors. That's in Linux. I should have said that I'm using Wing IDE Professional 4.

Re: [Tutor] Puzzled again

2011-08-03 Thread Dave Angel
On 08/03/2011 01:48 PM, Richard D. Moores wrote: On Wed, Aug 3, 2011 at 10:11, Peter Otten<__pete...@web.de> wrote: Dave was close, but Steven hit the nail: the string r"C:\Users\Dick\..." is fine, but when you put it into the docstring it is not a raw string within an

Re: [Tutor] adding dictionary value at position [-1]

2011-08-06 Thread Dave Angel
On 08/06/2011 07:32 AM, Norman Khine wrote: hello, i know that there are no indexes/positions in a python dictionary, what will be the most appropriate way to do this: addresses = {} for result in results.get_documents(): addresses[result.na

Re: [Tutor] commandline unable to read numbers?

2011-08-07 Thread Dave Angel
On 08/07/2011 01:00 AM, Steven D'Aprano wrote: Robert Sjoblom wrote: I have a quite odd problem, and I've come across it before but probably ignored it at the time because I had other concerns. I've tried googling for the answer but haven't really come closer to solving it. This is what happens:

Re: [Tutor] Using type

2011-08-12 Thread Dave Angel
On 08/12/2011 03:47 AM, Alan Gauld wrote: On 12/08/11 07:04, Emeka wrote: Hello All, I need help here, type(item) == [].__class__:. What is the idiomatic way of doing it? if type(item) == type([])... or in this case if type(item) == list... But probably preferrable to using type is to use

Re: [Tutor] Using type

2011-08-12 Thread Dave Angel
Oh, good catch Dave. So you'd want to add an explicit check for a string. And in fact you probably don't want to "flatten" a string into individual characters anyway! Alan G. I agree with you about probably not wanting to flatten a string. So I'd add an isinstance()

[Tutor] I am trying to read and decode an emails PDF attachment via python,

2011-08-20 Thread dave selby
and PDF data block but when I execute msg.is_multipart() I get False ??? And when I execute msg.get_payload() I get nothing Any ideas anyone, at a guess its because my string is not formatted correctly, can anyone advise ? Cheers Dave -- Please avoid sending me Word or PowerPoint attachments

Re: [Tutor] I am trying to read and decode an emails PDF attachment via python,

2011-08-20 Thread dave selby
Did a lot more digging and finally sorted it, sorry for bothering you guys, Cheers Dave On 20 August 2011 10:58, dave selby wrote: > I am trying to read and decode an emails PDF attachment via python, > its a dedicated mailbox, anything emailed there is to be read by the > script, del

Re: [Tutor] Please explain TypeError

2011-08-21 Thread Dave Angel
On 08/21/2011 05:35 PM, D. Guandalino wrote: Python documentation says: exception TypeError Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch. For example: 'foo' + (1, 2) Traceback (mo

Re: [Tutor] Raw input query (?)

2011-08-25 Thread Dave Angel
On 08/25/2011 05:46 AM, Lisi wrote: I copied and ran the following script: multiplier = 12 for j in range(1,13): print "%d x %d = %d" %(j, multiplier, j*multiplier) That ran perfectly and gave me the 12 times table. I then decided that it would be fun to branch out and make teh script "u

Re: [Tutor] String encoding

2011-08-26 Thread Dave Angel
On 08/26/2011 11:49 AM, Prasad, Ramit wrote: Yep, it is. Thanks those charts are exactly what I wanted! Now I have another question. What is the difference between what print shows and what the interpreter shows? print s.decode('latin-1') MÉXICO The decoded characters are a Unicode string.

Re: [Tutor] Get a single random sample

2011-09-09 Thread Dave Angel
On 09/09/2011 06:44 AM, kitty wrote: Hi, I'm new to python and I have read through the tutorial on: http://docs.python.org/tutorial/index.html which was really good, but I have been an R user for 7 years and and am finding it difficult to do even basic things in python, for example I want to imp

Re: [Tutor] Can't edit a file I've opened with open(), then closed with close()

2011-09-12 Thread Dave Angel
On 09/12/2011 01:29 AM, Richard D. Moores wrote: Win 7, Python 3.2.1 I'm trying to improve my skills with opening text files, reading from them, and writing to them. But while I'm doing this sometimes I want to manually modify the text file I'm using, C:\t\text.txt . Say I've done this: f = o

Re: [Tutor] Unusual pathfile

2011-09-13 Thread Dave Angel
1. Don't top-post. Put your response after whatever parts of a previous message you're quoting. And delete the parts that are no longer relevant. 2. If you used tabs in your code, convert to spaces before pasting into some email editors. Apparently your email editor is converting the tabs t

Re: [Tutor] making lists of prime numbers

2011-09-15 Thread Dave Angel
On 09/14/2011 10:35 PM, Andre Engels wrote: On Thu, Sep 15, 2011 at 4:01 AM, c smithwrote: hi list, i am trying the MIT opencourseware assignments. one was to find the 1000th prime. since this isn't actually my homework, I modified the solution as I would like to collect lists of primes and non

Re: [Tutor] range question

2011-09-22 Thread Dave Angel
On 09/22/2011 10:27 AM, Joel Knoll wrote: Given a range of integers (1,n), how might I go about printing them in the following patterns: 1 2 3 4 ... n2 3 4 5 ... n 13 4 5 6 ... n 1 2 etc., e.g. for a "magic square". So that for the range (1,5) for example I would get 1 2 3 42 3 4 13 4 1 24 1 2

Re: [Tutor] range question

2011-09-22 Thread Dave Angel
On 09/22/2011 10:43 AM, Hugo Arts wrote: forgot to forward to list: From: Hugo Arts Date: Thu, Sep 22, 2011 at 4:42 PM Subject: Re: [Tutor] range question To: d...@davea.name On Thu, Sep 22, 2011 at 4:37 PM, Dave Angel wrote: On 09/22/2011 10:27 AM, Joel Knoll wrote: Given a range of

Re: [Tutor] Need a bump in the right direction (network programming)

2011-09-23 Thread Dave Angel
On 09/23/2011 01:15 AM, Cheeyung wrote: I'm creating a mobile application and I'm using python for a desktop server. However, I don't have access to a static IP on the desktop, but do have a website. Is it possible to connect from mobile -> http website -> desktop server and back? What kind o

Re: [Tutor] Funtions, modules & global variables

2011-09-25 Thread Dave Angel
On 09/25/2011 07:21 PM, questions anon wrote: Hi All, I am trying to move from writing one long script each time I need to do a new thing but I do not quite understand how functions work, even after reading many manuals. My first attempt is to create a python file where I have defined a number of

Re: [Tutor] execute a function

2011-09-26 Thread Dave Angel
On 09/26/2011 06:53 AM, Sajjad wrote: Hello forum, It has been two days that i have started with python and i am stuck with the following simple issue: i have created a python file and inside the file i have defined a function as follows: //

Re: [Tutor] Funtions, modules & global variables

2011-09-26 Thread Dave Angel
(Don't top-post. Put your new remarks after whatever you're quoting) On 09/26/2011 08:26 PM, questions anon wrote: Thanks for your feedback. I might be asking the wrong questions. I have written a number of scripts that do various things for each step: 1. get data (e.g. Dec-jan-feb, only januar

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Dave Angel
On 09/29/2011 10:22 AM, lina wrote: Hi, I want to read a bunch of *.doc file in present working directory, how can I use for to read one by one and do further work, sorry, what's the best reference webpage I can use? I googled, lots of distracting info, and I barely can understand how they t

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Dave Angel
(Please don't top-post. Put your remarks AFTER the part you're quoting from the previous message) On 09/29/2011 10:55 AM, lina wrote: import os.path tokens=['E'] result=[] for fileName in os.listdir("."): if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm": fileda

Re: [Tutor] guess age programme (still stuck!!!!!)

2011-09-30 Thread Dave Angel
(Please don't top-post. Place your remarks after whatever quoting you do from the previous message. And trim the parts that are no longer relevant) On 09/30/2011 03:18 PM, ADRIAN KELLY wrote: please guys still stuck on this problem and i have been at it for hours so please if anyone can hel

Re: [Tutor] Input

2011-09-30 Thread Dave Angel
On 09/30/2011 03:24 PM, Cameron Macleod wrote: Hi, When you type Input("\n\nPress The Enter Key To Exit") it forces you to press the enter key to close the program. Why is it the enter key instead of e.g. the 'esc' key? The input() function (not the Input()) function accepts a line of text

Re: [Tutor] fake defrag revisited

2011-10-01 Thread Dave Angel
On 10/01/2011 02:06 AM, R. Alan Monroe wrote: I'm revisiting the fake defrag program I posted about a few months ago. The concept is basically a screensaver or light show where you can enjoy watching entropy being reversed as colored blocks order themselves visually. I set it aside for a while b

Re: [Tutor] fake defrag revisited

2011-10-01 Thread Dave Angel
On 10/01/2011 11:53 AM, R. Alan Monroe wrote: achieve the cosmetic randomness, until I realized the real problem is magically determining the correct sequence in which to perform the moves without ruining a future move inadverently. If I move 0-to-1 first, I've now ruined the future 1-to-22 whic

Re: [Tutor] arrary stastic

2011-10-04 Thread Dave Angel
On 10/04/2011 12:01 PM, bob gailer wrote: On 10/4/2011 10:07 AM, lina wrote: want to do a statistic of the concurrence of E, namely, how many times the E showed up, so the first column is 1, second column and then following. Thanks, I have one, which showed something like

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 10:26 AM, lina wrote: On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel wrote: (Please don't top-post. Put your remarks AFTER the part you're quoting from the previous message) On 09/29/2011 10:55 AM, lina wrote: import os.path tokens=['E'] result=[] for fi

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 01:09 PM, lina wrote: But I still don't know how to get the statistic result of each column, Thanks for further suggestions, Best regards, lina As I said before, your current code counts across a line at a time, while you need to count vertically. That could be done by transpo

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 10:22 PM, lina wrote: On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramitwrote: But I still don't know how to get the statistic result of each column, Thanks. try: cols = len( text[0] ) # Find out how many columns there are (assuming each row has the same number of columns) except

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-04 Thread Dave Angel
On 10/04/2011 11:13 PM, lina wrote: On Wed, Oct 5, 2011 at 10:45 AM, Dave Angel wrote: On 10/04/2011 10:22 PM, lina wrote: On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramit w SyntaxError: invalid syntax for fileName in os.listdir("."): if os.path.isfile(fileName) and os.pat

Re: [Tutor] fake defrag revisited

2011-10-04 Thread Dave Angel
On 10/01/2011 03:53 PM, R. Alan Monroe wrote: You missed the rest of the paragraph. Don't wait for the sort to finish, you do the swapping in the compare function. Either I'm too dumb to understand your answer, or explained my original problem too poorly. Have you ever played the Rush Hour

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread Dave Angel
On 10/05/2011 02:51 AM, lina wrote: On Wed, Oct 5, 2011 at 1:42 PM, Dave Angel wrote: On 10/04/2011 11:13 PM, lina wrote: On Wed, Oct 5, 2011 at 10:45 AM, Dave Angel wrote: On 10/04/2011 10:22 PM, lina wrote: On Wed, Oct 5, 2011 at 1:30 AM, Prasad, Ramit *com w SyntaxError

Re: [Tutor] fake defrag revisited

2011-10-05 Thread Dave Angel
On 10/05/2011 07:58 AM, R. Alan Monroe wrote: Since all the moves are swaps, it'll be guaranteed to be in a sequence that converges on the correct final order. Will it be the minimum number of moves? Definitely not. But that wasn't a requirement, and if it were, you wouldn't start by building t

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-05 Thread Dave Angel
On 10/05/2011 08:46 AM, lina wrote: On Wed, Oct 5, 2011 at 8:21 PM, Dave Angel wrote: #these two are capitalized because they're intended to be constant TOKENS = "BE" LINESTOSKIP = 43 INFILEEXT = ".xpm" OUTFILEEXT = ".txt" def dofiles(topdirect

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-06 Thread Dave Angel
On 10/06/2011 12:21 PM, lina wrote: As for splitting into functions, consider: #these two are capitalized because they're intended to be constant TOKENS = "BE" LINESTOSKIP = 43 INFILEEXT = ".xpm" OUTFILEEXT = ".txt" def dofiles(topdirectory): for filename in os.listdr(topdirectory):

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Dave Angel
On 10/07/2011 04:08 AM, lina wrote: I thought it might be some loop reason made it double output the results, so I made an adjustation in indent, now it showed: $ python3 counter-vertically-v2.py {'B': [0, 0, 0, 0, 0, 0], 'E': [1, 0, 1, 0, 1, 0]} {'B': [0, 0, 0, 0, 0, 0], 'E': [1, 0, 1, 0, 1, 0]

Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-10-07 Thread Dave Angel
On 10/07/2011 06:06 AM, Alan Gauld wrote: On 07/10/11 09:08, lina wrote: summary=[] for a,b in zip(results['E'],results['B']): summary.append(a+b) I don't know why this gives a key error on 'E' (which basically means that there is no key 'E') since the code above should gu

Re: [Tutor] String switch

2011-10-08 Thread Dave Angel
On 10/08/2011 03:03 PM, Christopher King wrote: Okay, here's what I what to do *--Target.py--* print "Hello World" *--Target.py Output--* *Hello World* *--Main.py--* target=open("target.py", "r") old=target.read() target.close() target=open("target.py", "w") target.write(''' Str.__repr__ = Str.__

Re: [Tutor] String switch

2011-10-09 Thread Dave Angel
On 10/09/2011 11:27 AM, Christopher King wrote: I know the method of finding every string, and inserting a swapcase in to the code. Does anyone now a way just to insert code at the top though? P.S. I use python 2.* Would you consider answering the rest of my questions? Since this is obviousl

Re: [Tutor] String switch

2011-10-10 Thread Dave Angel
On 10/10/2011 08:56 PM, Christopher King wrote: Okay, there is a python file called target.py. In the same directory there is a file named main.py. You are the author of main.py. The code in main.py will write to target.py. Then the antivirus catches main.py and removes, but not the modification

Re: [Tutor] map one file and print it out following the sequence

2011-10-12 Thread Dave Angel
On 10/12/2011 09:57 AM, lina wrote: I do have problems to write each blocks (differentiated by chainID) back one by one, but this will leave it at the end. at present I still have following problems Q1: why the D E F G H I stopped being processed. In what sense do you mean stopped? There are

Re: [Tutor] extract specific column

2011-10-12 Thread Dave Angel
On 10/12/2011 03:59 PM, Anna Olofsson wrote: (PLEASE don't top-post. And don't start multiple similar threads a couple of hours apart. Send your message as text without tons of blank lines, and don't assume the attachments will make it. In my case, I haven't a clue to what the file looks li

Re: [Tutor] map one file and print it out following the sequence

2011-10-13 Thread Dave Angel
On 10/13/2011 09:09 AM, lina wrote: I think your final version of sortfile() might look something like: def sortfile(infilename=**INFILENAME, outfilename=OUTFILENAME): infile = open(infilename, "r") intext = infile.readlines() outfile = open(OUTFILENAME, "w") for chainid in CH

Re: [Tutor] problem with using set

2011-10-13 Thread Dave Angel
On 10/13/2011 10:44 AM, Praveen Singh wrote: 2. a='microsoft' set(a) set(['c', 'f', 'i', 'm', 'o', 's', 'r', 't']) print ''.join(set(a)) cfimosrt When i print "Hello", i get the output as "helo"(in same sequence) but when i write "microsoft" i get this-"cfimosrt". So, it means i can't pred

Re: [Tutor] 'object' class

2011-10-14 Thread Dave Angel
On 10/14/2011 10:17 AM, Rafael Durán Castañeda wrote: 2011/10/14 Max S. I have seen classes created with 'class Class_Name:' and 'class Class_Name(object):'. I'm using the latter, just in case it has some sort of method that could be useful that I don't know about, but *are *there any methods

Re: [Tutor] A better way to estimate the value of Pi?

2011-10-17 Thread Dave Angel
On 10/17/2011 11:55 AM, Sagar Shankar wrote: The "real" value of 4/3.0 is 1 followed by an unending number of 3's. Each successive fraction's floating point value will be "off" by some relatively small value. Those errors will probably add up. Another limitation of floating point numbers is

Re: [Tutor] close failed in file object destructor:

2011-10-18 Thread Dave Angel
On 10/18/2011 01:59 PM, Navneet wrote: Hi, I am trying to search a list for prime numbers but it's throwing me an error at line no.25. I am not able to figure what exactly is the prob ne help ??? Error is this: $ python "prime1 - Copy.py" Unhandled exception in thread started by Traceback (mos

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-22 Thread Dave Angel
On 10/22/2011 06:10 PM, Chris Kavanagh wrote: Hello, First, thank you for providing this GREAT service, & THANKS to everyone who contributes. It's greatly appreciated. . .I'm new to Python (2.7, Win XP) & new to programming in general. I have been studying on my own for about a month now. I bel

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-23 Thread Dave Angel
: Sun, 23 Oct 2011 16:53:40 -0400 From: Chris Kavanagh Organization: Home Office To: d...@davea.name On 10/22/2011 6:59 PM, Dave Angel wrote: My question is regarding the tell methods in the subclasses,the code {SchoolMember.tell(self)}, in the class Teacher & Student. I just don't u

Re: [Tutor] how to unique the string

2011-10-23 Thread Dave Angel
On 10/23/2011 08:01 AM, lina wrote: On Sun, Oct 23, 2011 at 6:06 PM, Peter Otten<__pete...@web.de> wrote: lina wrote: tobetranslatedparts=line.strip().split() strip() is superfluous here, split() will take care of the stripping: " alpha \tbeta\n".split() ['alpha', 'beta'] for residue in

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Dave Angel
On 10/24/2011 09:10 AM, Praveen Singh wrote: In Dictionary- How to print corresponding keys if the values of dictionary is given?? -d={'a':1,'b':2,'c':3} -i can print the corresponding values by using get() method- - d.get('a') -1 What if i have to print reverse??? A dictionary can be viewed

Re: [Tutor] How to print corresponding keys in Dictionary

2011-10-24 Thread Dave Angel
(You forgot to include the list on your reply. Easiest way is to do a reply-all when you're replying) On 10/24/2011 12:21 PM, Praveen Singh wrote: On Mon, Oct 24, 2011 at 9:18 AM, Dave Angel wrote: def getkey(dictionary, value): for key, val in dictionary.items():

Re: [Tutor] string immutability

2011-10-24 Thread Dave Angel
On 10/24/2011 02:04 PM, 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? You're c

Re: [Tutor] string immutability

2011-10-24 Thread Dave Angel
after initializing/assigning it a value. s = "First" print s.__class__ print s First s = "Second" print s Second Dave, Sander and Wayne have already explained why you aren't modifying string objects in your example. With the id()-function you can also see

Re: [Tutor] Simple Question On A Method (in subclass)

2011-10-25 Thread Dave Angel
On 10/25/2011 12:20 AM, Chris Kavanagh wrote: On 10/24/2011 12:06 AM, Marc Tompkins wrote: On Sun, Oct 23, 2011 at 8:08 PM, Chris Kavanagh My problem was, I wasn't seeing {member} as referring to the class objects {t} and {s}. Since it was, we now can use member just like any class object

Re: [Tutor] What is wrong with my code?

2011-10-25 Thread Dave Angel
(Once again, please don't top-post. It makes your responses out of order) On 10/25/2011 04:24 AM, apometron wrote: I did it very much times, Anssi. Beyond of run it on Python 2.7 latest build, what do you suggest? Do install Python 3.2 along the Python 2.7 installation could give me any prob

Re: [Tutor] how to calculate execution time and complexity

2011-10-28 Thread Dave Angel
On 10/28/2011 01:38 AM, Praveen Singh wrote: splitWord('google', 2) ['go', 'og', 'le'] >>> splitWord('google', 3) ['goo', 'gle'] >>> splitWord('apple', 1) ['a', 'p', 'p', 'l', 'e'] >>> splitWord('apple', 4) ['appl', 'e'] def splitWord(word, number):

Re: [Tutor] Tutor Digest, Vol 92, Issue 128

2011-10-31 Thread Dave Angel
On 10/31/2011 06:09 PM, Alan Gauld wrote: On 31/10/11 20:55, Steven D'Aprano wrote: You may prefer to change to individual emails instead of digest mode. In my opinion, digest mode is only useful when you want to read other people's comments without commenting yourself. It depends, I've used

Re: [Tutor] Help

2011-11-01 Thread Dave Angel
(Pleas put your reply after the part you're quoting. What you did is called top-posting, and makes reading the messages very confusing) On 11/01/2011 12:10 AM, Chris Kavanagh wrote: I'm going to thank Steven once again, and answer my own question in the 2nd paragraph directly below (Steven hasn

Re: [Tutor] A question about sys.argv

2011-11-01 Thread Dave Angel
On 11/01/2011 10:05 AM, Hugo Arts wrote: On Tue, Nov 1, 2011 at 2:48 PM, Jefferson Ragot wrote: In a Vista command prompt if I typed this: >>> python somescript.py filename Will sys.argv[1] return a valid path or just the filename? If it just returns the filename, is there a simpl

Re: [Tutor] A question about sys.argv

2011-11-01 Thread Dave Angel
On 11/01/2011 10:19 AM, Jose Amoreira wrote: HiOn Tuesday, November 01, 2011 01:55:18 PM Joel Goldstick wrote: On Tue, Nov 1, 2011 at 9:48 AM, Jefferson Ragot wrote: In a Vista command prompt if I typed this: >>> python somescript.py filename Will sys.argv[1] return a valid path o

Re: [Tutor] improve the code

2011-11-01 Thread Dave Angel
On 11/01/2011 10:11 AM, lina wrote: Hi, The following code (luckily) partial achieved what I wanted, but I still have few questions: #!/usr/bin/python3 import os.path INFILEEXT=".txt" OUTFILEEXT=".new" DICTIONARYFILE="dictionary.pdb" orig_dictionary={} new_dictionary={} abetaABresidues={} d

Re: [Tutor] improve the code

2011-11-01 Thread Dave Angel
On 11/01/2011 11:11 AM, lina wrote: On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel wrote: On 11/01/2011 10:11 AM, lina wrote: Hi, The following code (luckily) partial achieved what I wanted, but I still have few questions: #!/usr/bin/python3 import os.path INFILEEXT=".txt" OUTFIL

Re: [Tutor] improve the code

2011-11-01 Thread Dave Angel
On 11/01/2011 11:11 AM, lina wrote: On Tue, Nov 1, 2011 at 10:33 PM, Dave Angel wrote: On 11/01/2011 10:11 AM, lina wrote: Hi, The following code (luckily) partial achieved what I wanted, but I still have few questions: #!/usr/bin/python3 import os.path INFILEEXT=".txt" OUTFIL

Re: [Tutor] improve the code

2011-11-02 Thread Dave Angel
On 11/02/2011 11:54 AM, lina wrote: Regard the sorted(), I still have a question, how to sort something like results ['1A', '10B', '2C', '3D'] sorted(results) ['10B', '1A', '2C', '3D'] as [ '1A', '2C', '3D','10B'] Thanks, mainly based on their digital value. Peter answered essential

Re: [Tutor] binding problem

2011-11-03 Thread Dave Angel
(You mistakenly top-posted, so now in order to keep this next message in order, I have to delete the out of order history) On 11/03/2011 09:01 AM, Chris Hare wrote: Thanks for the advice. When I do that, I get this error Exception in Tkinter callback Traceback (most recent call last): File

Re: [Tutor] how to separate the digital and the alphabeta

2011-11-03 Thread Dave Angel
On 11/03/2011 12:30 PM, lina wrote: Hi, ['1AB','57GL', '76LE'] How can I extract 1, 57 , 76 out? except the one I tried as: for i in range(len(a)): print(a[i][:-2]) 1 57 76 are there some way to tell the difference between the [0-9] and [A-Z], In the last thread, somebod

Re: [Tutor] how to separate the digital and the alphabeta

2011-11-03 Thread Dave Angel
On 11/03/2011 12:37 PM, lina wrote: I have another question, regarding the generator, def translate_process(dictionary,tobetranslatedfile): results=[] with open(tobetranslatedfile,"r") as f: results=(dictionary[line.split()[2]] for line in f) print(list(results))

Re: [Tutor] improve the code

2011-11-03 Thread Dave Angel
On 11/03/2011 10:39 PM, lina wrote: On Wed, Nov 2, 2011 at 12:14 AM, Peter Otten<__pete...@web.de> wrote: lina wrote: items [('83ILE', 1), ('84ALA', 2), ('8SER', 0), ('9GLY', 0)] parts = re.split(r"(\d+)",items) Traceback (most recent call last): File "", line 1, in parts = re.s

Re: [Tutor] regexp

2011-11-04 Thread Dave Angel
On 11/04/2011 07:00 PM, Steven D'Aprano wrote: Dinara Vakhitova wrote: Hello, I need to find the words in a corpus, which letters are in the alphabetical order ("almost", "my" etc.) Quoting Jamie Zawinski: Some people, when confronted with a problem, think "I know, I'll use regular

Re: [Tutor] Writing processed text to another file(beginner)

2011-11-05 Thread Dave Angel
On 11/05/2011 03:04 PM, Mayo Adams wrote: Code to build a list z to contain all the first words in each line of a text file: z=[] f=open('C:/atextfile.txt') for aLine in f: str=aLine a=str.split() z.append(a) I would like to work further with the list z once the file has been stripped, an

Re: [Tutor] Writing processed text to another file(beginner)

2011-11-05 Thread Dave Angel
On 11/05/2011 03:31 PM, Mayo Adams wrote: Thank you for your reply, this is all I needed to know: the loop is over when you outdent back to line up with the for statement Indeed, the indentation rules are very simple. I just wanted to be sure about what they were. Sounds good. Three

Re: [Tutor] Having trouble visiting the subscribers list.

2011-11-05 Thread Dave Angel
On 11/05/2011 08:57 PM, Nathaniel Trujillo wrote: I recently subscribed to tutor and I am trying to visit the subscribers list so I can ask a question but I was'nt given an admin address. Not only that but I don't know what an admin address is. Your help is greatly appreciated. You've figured o

Re: [Tutor] getting nasty TypeError:

2011-11-05 Thread Dave Angel
On 11/05/2011 10:02 PM, Nathaniel Trujillo wrote: Hello. I am currently working with Python version 3.1.1 . I am working out of the book called Python Programming for the Absolute Beginner Third Edition which teaches version 3.1.1 . I wrote the following blackjack program that is on page 275 and

Re: [Tutor] Printing with no newline :(

2011-11-06 Thread Dave Angel
On 11/06/2011 04:45 AM, Sarma Tangirala wrote: On 6 November 2011 13:11, Peter Otten<__pete...@web.de> wrote: Joe Batt wrote: I am learning Python 3 and programming and am very new so please bear for item in items: ... print(item, end="WHATEVER") Another way of writing the above.

Re: [Tutor] Printing with no newline :(

2011-11-06 Thread Dave Angel
On 11/06/2011 05:23 AM, Sarma Tangirala wrote: python 3 . Please bear with me on this, but does the following not print "end" for every iteration of "items"? for item in items: print(item, end="") Sure it does. And the value of end is the empty string. So it prints nothing but th

Re: [Tutor] Printing with no newline :(

2011-11-06 Thread Dave Angel
On 11/06/2011 05:23 AM, Sarma Tangirala wrote: I just joined the list and did WELCOME to the list. I should have said that first. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.pyth

Re: [Tutor] tkfiledialogs and hidden files

2011-11-08 Thread Dave Angel
On 11/07/2011 09:45 PM, Jose Amoreira wrote: Hello! Is there any way to configure tkFileDialogs so that they don't display hidden files? Thanks. Ze Amoreira I can't help you with tk, but maybe I can help you ask a better question. "Hidden files" means a different thing on various operating sys

Re: [Tutor] string split function - how to tell how many splits

2011-11-08 Thread Dave Angel
On 11/08/2011 11:56 AM, Cranky Frankie wrote: How do you tell how many splits the string split funtion returns? For example: field = 'The Good Wife ;' # a string separated by spaces new_list = field.split(' ') # create a list of space delimited elements print (new_list[0])

Re: [Tutor] positional output

2011-11-10 Thread Dave Angel
On 11/10/2011 03:54 PM, Cranky Frankie wrote: What is the easiest way in Python 3.x to write output positionally? For example I have one literal I want in column 1, the next one in column 40, the third one in column 50. I've tried usings tabs and I'm not getting what I want. Is it something to do

Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Dave Angel
On 11/10/2011 08:01 PM, Nathaniel Trujillo wrote: Okay, I typed into the command line of version 2.7.2, python -c "import sys; print sys.version". I tried it with and without the quotes. I tried copying the error messages from the command line but it wouldn't let me so I copied them from the pyth

Re: [Tutor] longest common substring

2011-11-12 Thread Dave Angel
On 11/12/2011 03:54 AM, lina wrote: The one I tried : if longest>= 2: sublist=L1[x_longest-longest:x_longest] result=result.append(sublist) if sublist not in sublists: sublists.append(sublis

Re: [Tutor] longest common substring

2011-11-12 Thread Dave Angel
On 11/12/2011 09:48 AM, lina wrote: On Sat, Nov 12, 2011 at 9:22 PM, Dave Angel wrote: On 11/12/2011 03:54 AM, lina wrote: The one I tried : if longest>= 2: sublist=L1[x_longest-longest:x_longest] result=result.append(subl

Re: [Tutor] longest common substring

2011-11-13 Thread Dave Angel
On 11/13/2011 08:06 AM, lina wrote: Finally, if I am not wrong again, I feel I am kinda of starting figuring out what's going on. Why it's None. The main mistake here I use result = result.append(something) the "=" I checked the print(id(result)) and print(id(result.append()), For the NoneTyp

Re: [Tutor] Trouble installing Python on Win7 (not a valid Win 32 app)

2011-11-15 Thread Dave Angel
On 11/15/2011 10:47 AM, Wayne Watson wrote: > Highlight the line for ".py". Click the button (yes, the one that says "Change > program..."). You'll Yes, did that. > get another dialog box, and in that one there will be a button labeled > "Browse". Click it. This will open up an "Open with.

Re: [Tutor] Clock in tkinter?

2011-11-16 Thread Dave Angel
Top-posting is what I'm doing here. Putting my remarks BEFORE the part I'm quoting. On 11/16/2011 12:44 PM, Mic wrote: Oh, by top-posting you mean that I include everything I have written before in my post, and that it is no good to do? So I just post what I wrote, and nothing from earli

Re: [Tutor] Multiple threads

2011-11-16 Thread Dave Angel
(You're top-posting. Put your remarks AFTER what you're quoting) On 11/16/2011 12:52 PM, Jack Keegan wrote: Ok, I thought that processes would do the same job as threads. So would the general rule be some thing like so: If I want another piece of work to run (theoretically) along side my main

Re: [Tutor] Rot13

2011-11-17 Thread Dave Angel
On 11/17/2011 12:54 PM, Nidian Job-Smith wrote: Sorry about the code format in last E-mail. I'll attach the code in notepad, as my e-mail doesnt seem to like sending plain text.. But attachments aren't visible to everyone on the list, and even when they are, some people are (rightfully) parano

Re: [Tutor] local variable referenced before assignment

2011-11-17 Thread Dave Angel
On 11/17/2011 01:47 PM, ADRIAN KELLY wrote: hi all,keep getting the above error, can't understand or fix it, can anyone help. def exchange():euro=1dollar=1.35base=50amount = input ('how much do you want to change')if amount>base:totalreturn=amount*dollar else:

Re: [Tutor] Doctest error!

2011-11-17 Thread Dave Angel
On 11/18/2011 10:29 AM, John wrote: Hi all, When i run a doctest on this piece of code (shown at bottom) i get this error message [from the doctest]: Trying: rot13('5 The Parade') Expecting: '5 Gur Cnenqr' ** File "

Re: [Tutor] infinite loop

2011-11-17 Thread Dave Angel
On 11/17/2011 04:29 PM, ADRIAN KELLY wrote: #i am nearly there guys..please loop at the infinite loop i am getting here..PLEASE!!#ADRIAN def exchange(cash_in):euro=1dollar=float(1.35)base=50if cash_in>base:totalreturn=cash_in*dollarelse:

Re: [Tutor] Doctest error!

2011-11-17 Thread Dave Angel
On 11/17/2011 10:56 PM, Nidian Job-Smith wrote: Date: Thu, 17 Nov 2011 22:49:33 -0500 From: d...@davea.name To: nidia...@hotmail.com CC: tutor@python.org Subject: Re: [Tutor] Doctest error! On 11/18/2011 10:29 AM, John wrote: Hi all, When i run a doct

Re: [Tutor] Shorten Code.

2011-11-18 Thread Dave Angel
On 11/18/2011 04:01 AM, Alan Gauld wrote: On 18/11/11 08:16, Mic wrote: What if I don’t write the same line of code more than once, but I write similiar lines more than once. Is that okay? Ler For example: value="green” value_1=”green” If you had a lot of these you could shorten it with a loo

Re: [Tutor] A recursion question

2011-11-18 Thread Dave Angel
On 11/18/2011 08:16 AM, Kĩnũthia Mũchane wrote: Hi, I am trying to do something which is really stupid :-) I would like to count the number of occurrences of a certain character in a list. This is more of an exercise in recursion rather than the underlying problem. I could have used a *for* l

Re: [Tutor] In a pickle over pickles….Python 3

2011-11-18 Thread Dave Angel
On 11/18/2011 11:12 AM, Joe Batt wrote: Hi All,Sorry to trouble you all again with more nooby problems! Only been programming a week so still all a haze especially since self taught….. I am opening a url and saving it to a file on my computer, then I am trying to pickle it. I have written the u

Re: [Tutor] A recursion question

2011-11-19 Thread Dave Angel
] == val: return 1 + counter(mylist[1:], val) else: return counter(mylist[1:]) The intermediate variable explanation by Dave actually clinched it for me. Actually, the one I wrote is suspiciously similar to yours ;-). Anyway, thanks Asokan! FWIW, Asokan's code

[Tutor] \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character ?

2011-11-20 Thread dave selby
nd 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.o

<    4   5   6   7   8   9   10   11   12   13   >