[Tutor] Grabbing Info from Text files?
Hello, I have been getting lost when trying to find the needed information on how to grab information from text files to be used in a python script I am working on. Essentially the script is calling upon other programs to grab specific information about files and putting that information into basic text files. When I say basic I mean basic, each piece of information has its own line such as: InfoOne=? InfoTwo=? Where the ? is a value ranging from 1 character up to 5 (usually numbers), and it is the value I represented with ? that I need to grab. I am hoping it is possible to grab 1 line at a time so variables can be set for use later in my script. I have tried to decipher the python documents on this, but honestly, being a dabbler in python I am getting lost, dazed and confused as friends would put it. Thankfully this is not for any homework assignments, it is merely a script I am working on for making some repetitive tasks more automated, such as grabbing information about video files, and if needed convert them. I have yet to find a program that does what I am aiming for so I started creating a python script (as python is already installed on my Linux distro). It just seems to have become more complicated that I had hoped, but I am at a point now were I do not want to leave it unfinished. If an example of my script is needed I am more than willing to provide it for clarification of what I am trying to do. Thanks, Mike ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 48
Re:please, send me programms as a file ( like word.py ) for easy understanding of the programmes. On 11/12/10, tutor-requ...@python.org tutor-requ...@python.org wrote: Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-requ...@python.org You can reach the person managing the list at tutor-ow...@python.org When replying, please edit your Subject line so it is more specific than Re: Contents of Tutor digest... Today's Topics: 1. Re: A deeper explanation of ability to modify list elements in-place (Steven D'Aprano) 2. Re: Creating one file out of all the files in a directory (Kushal Kumaran) 3. Re: A deeper explanation of ability to modify list elements in-place (Serdar Tumgoren) 4. What is a state variable? (Richard D. Moores) 5. Re: What is a state variable? (Emile van Sebille) -- Message: 1 Date: Fri, 12 Nov 2010 04:41:34 +1100 From: Steven D'Aprano st...@pearwood.info To: Python Tutor Tutor@python.org Subject: Re: [Tutor] A deeper explanation of ability to modify list elements in-place Message-ID: 4cdc2ace.6030...@pearwood.info Content-Type: text/plain; charset=ISO-8859-1; format=flowed Serdar Tumgoren wrote: But I think I see your point. The list object behaves the same as the objects stored inside the list. Er, surely not... the list object is a list, the objects inside the list are ints. They do not behave the same. In other words, the list object is a reference to an ordered sequence of object references, and you're operating on those (referenced) objects rather than copies of the objects when you iterate over the list. Is that correct? If so, no doubt there's a simpler way to say all that? A list is an ordered sequence of objects. When you iterate over the list, you see the contents of the list, not copies. Python never copies objects unless you explicitly tell it to. -- Steven -- Message: 2 Date: Thu, 11 Nov 2010 18:37:13 +0530 From: Kushal Kumaran kushal.kuma...@gmail.com To: Josep M. Fontana josep.m.font...@gmail.com, tutor@python.org Subject: Re: [Tutor] Creating one file out of all the files in a directory Message-ID: 1289480833.13521.5.ca...@nokia-n900 Content-Type: text/plain; charset=utf-8 - Original message - Hi, I'm trying to create a script to do the following. I have a directory containing hundreds of text files. I need to create a single file with the contents of all the files in the directory. Within that file, though, I need to create marks that indicate the division between the contents of each file that has wound up in that single file. Your current code adds the marker line to the original files. Is that intended? You can open the output file for writing by passing 'w' as the second argument to open. You would do this before your directory-walking loop. Then when you read the contents of any file, just write to your output file as well, along with your marker line. I got this far but I'm stumped to continue: - code import os path = '/Volumes/DATA/MyPath' os.chdir(path) file_names = glob.glob('*.txt') output_stream = open('outputfilename', 'w') for subdir, dirs, files in os.walk(path): ? ? ? ? for file in files: ? ? ? ? ? ? ? ? f = open(file, 'r') ? ? ? ? ? ? ? ? text = f.readlines() output_stream.writelines(text) output_stream.write('__\n') ? ? ? ? ? ? ? ? f.close() ? ? ? ? ? ? ? ? f = open(file, 'a') ? ? ? ? ? ? ? ? f.write('\n\n' + '' + '\n') ? ? ? ? ? ? ? ? f.close() output_stream.close() What's missing here is obvious. This iterates over all the files and creates the mark for the division at the end of each file. There is nothing, however, to pipe the output of this loop into a new file. I've checked the different manuals I own plus some more on the internet but I can't figure out how to do what's left. I could get by with a little help from my Tutor friends. -- next part -- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/2010/bdb2f06a/attachment-0001.html -- Message: 3 Date: Thu, 11 Nov 2010 14:21:22 -0500 From: Serdar Tumgoren tumgor...@washpost.com To: Steven D'Aprano st...@pearwood.info Cc: Python Tutor Tutor@python.org Subject: Re: [Tutor] A deeper explanation of ability to modify list elementsin-place Message-ID: aanlktikuphqzcu-mgy1h7ozpsfsuxra59gnc27yvq...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 First off, thanks for the detailed response! I had a few follow-up
Re: [Tutor] A deeper explanation of ability to modify list elementsin-place
Serdar Tumgoren tumgor...@washpost.com wrote So is a reference simply a Python-level symbol (ie some collections of characters accessible from Python code) that corresponds to a pointer, which in turn points to the location in memory where the object is stored? Or to think of it in Python terms a reference or name is simply a key in a dictionary, with one such dictionary per namespace. When you do a dir() you are asking for the keys - the names - in that namespace. The objects that the names refer to are the values in the dictionary. But then it gets circular since the dictionary does not store the objects, just references to the objects - but those references could be pointers depending on implementation :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is a state variable?
Richard D. Moores rdmoo...@gmail.com wrote Is k then a state variable in that its state is 23? What sorts of variables are, and are not, state variables? The concept of a state variable seems central to Kent's article. If only I knew exactly what it was. First, do you understand what ste is in mathematical/computing terms? That is critical to understanding what state variables are? For example if I say that the state of any object can be represented by a vector whose values correspond to the collected set of variables of the object, does that make sense? If not, we need to go back to consider what state is and why it is important in computing. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 48
marupalli charan marupalli.cha...@gmail.com wrote Re:please, send me programms as a file ( like word.py ) for easy understanding of the programmes. Please read the instructions below and follow them. And please remove extraneous content. That way you asre more likely to get a listening ear. You have many sample python scripts in your python distribution if you want to study code. There are also more complex examples on Sourceforge. Search for projects using Python. On 11/12/10, tutor-requ...@python.org tutor-requ...@python.org wrote: Send Tutor mailing list submissions to tutor@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/tutor or, via email, send a message with subject or body 'help' to tutor-requ...@python.org You can reach the person managing the list at tutor-ow...@python.org When replying, please edit your Subject line so it is more specific than Re: Contents of Tutor digest... Today's Topics: -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Grabbing Info from Text files?
On 12/11/2010 08:28, Michael Stover wrote: Hello, I have been getting lost when trying to find the needed information on how to grab information from text files to be used in a python script I am working on. Essentially the script is calling upon other programs to grab specific information about files and putting that information into basic text files. When I say basic I mean basic, each piece of information has its own line such as: InfoOne=? InfoTwo=? Where the ? is a value ranging from 1 character up to 5 (usually numbers), and it is the value I represented with ? that I need to grab. I am hoping it is possible to grab 1 line at a time so variables can be set for use later in my script. I have tried to decipher the python documents on this, but honestly, being a dabbler in python I am getting lost, dazed and confused as friends would put it. Thankfully this is not for any homework assignments, it is merely a script I am working on for making some repetitive tasks more automated, such as grabbing information about video files, and if needed convert them. I have yet to find a program that does what I am aiming for so I started creating a python script (as python is already installed on my Linux distro). It just seems to have become more complicated that I had hoped, but I am at a point now were I do not want to leave it unfinished. If an example of my script is needed I am more than willing to provide it for clarification of what I am trying to do. Thanks, Mike ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor If you can ensure that a header is written to those text files so they're in format such as [SectionHeader] InfoOne=Value InfoTwo=Value ... then you can take a look at the ConfigParser module where you would simply read the file and all your values would be read in in neat pairs. $ cat test.conf [Blah] OptOne=1 OptTwo=2 OptThree=3 $ python Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11) [GCC 4.4.1] on linux2 Type help, copyright, credits or license for more information. from ConfigParser import ConfigParser cfg = ConfigParser() cfg.read('test.conf') ['test.conf'] cfg.items('Blah') [('optone', '1'), ('optthree', '3'), ('opttwo', '2')] The other way to do it yourself is to iterate over the lines in the file, split the key and value and store it in a dictionary for later use. -- Kind Regards, Christian Witts ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
Richard D. Moores wrote: I find using that at the interactive prompt a bit onerous -- lots of copy and pasting. And doubly so when comparing times for 2 or more functions. Does your Python not support readline? Normally, if you press UP ARROW or DOWN ARROW, Python will cycle through the previous interpreter lines. Another approach is to write helper functions, or use string interpolation, to make it easy to re-use code: setup = from __main__ import %s as func test = func(1000) t1 = Timer(test, setup % my_func) t1 = Timer(test, setup % your_func) A third approach might be to treat your testing as a script. Put all your test code in a module, and then run it: python time_test.py The timeit doc gave me the obvious idea of how to avoid the prompt and also easily compare the times of 2 or more functions. I'd like to know if doing it this way is correct: Please see http://tutoree7.pastebin.com/84u1fkgA You're vulnerable to statistical outliers (which are remarkably common on multi-tasking operating systems!) cause by the OS calling some other program in the middle of yours. Call each time test three or five times, and use the smallest. Huh. Just realized that this timing method doesn't include the 5 repeats called for by Steven's method. So how about using a for loop? As in http://tutoree7.pastebin.com/J8bPKUqC. You're still re-inventing the wheel. timeit already includes a method for doing exactly that: repeat. From the documentation: def repeat(self, repeat=default_repeat, number=default_number): Call timeit() a few times. This is a convenience function that calls the timeit() repeatedly, returning a list of results. ... 97% of the time you think you want to call timeit, you actually should be calling min(timer.repeat()) instead. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
On Fri, Nov 12, 2010 at 02:11, Steven D'Aprano st...@pearwood.info wrote: Richard D. Moores wrote: I find using that at the interactive prompt a bit onerous -- lots of copy and pasting. And doubly so when comparing times for 2 or more functions. Does your Python not support readline? Normally, if you press UP ARROW or DOWN ARROW, Python will cycle through the previous interpreter lines. Do you mean my IDE? IDLE does that with Alt+P and Alt+N. I'm dealing with multi-line functions, not single lines. If I paste a function at the prompt, IDLE will bring the whole thing back with Alt+P. Problem is, IDLE isn't my IDE -- Wing is. Another approach is to write helper functions, or use string interpolation, to make it easy to re-use code: setup = from __main__ import %s as func test = func(1000) t1 = Timer(test, setup % my_func) t1 = Timer(test, setup % your_func) A third approach might be to treat your testing as a script. Put all your test code in a module, and then run it: python time_test.py OK, but why can't I do what the timeit doc suggests, only put 2 or more functions in the file, as I do here: http://tutoree7.pastebin.com/84u1fkgA def test(): Stupid test function L = [] for i in range(100): L.append(i) if __name__=='__main__': from timeit import Timer t = Timer(test(), from __main__ import test) print t.timeit() The timeit doc gave me the obvious idea of how to avoid the prompt and also easily compare the times of 2 or more functions. I'd like to know if doing it this way is correct: Please see http://tutoree7.pastebin.com/84u1fkgA You're vulnerable to statistical outliers (which are remarkably common on multi-tasking operating systems!) cause by the OS calling some other program in the middle of yours. Call each time test three or five times, and use the smallest. Sure, I do that with the for loops, don't I? Huh. Just realized that this timing method doesn't include the 5 repeats called for by Steven's method. So how about using a for loop? As in http://tutoree7.pastebin.com/J8bPKUqC. You're still re-inventing the wheel. timeit already includes a method for doing exactly that: repeat. From the documentation: def repeat(self, repeat=default_repeat, number=default_number): Call timeit() a few times. This is a convenience function that calls the timeit() repeatedly, returning a list of results. ... I'm sorry, Steven, but I could you revise this code to use repeat=5 instead of the for loop? I can't see how to do it. if __name__=='__main__': from timeit import Timer for y in range(5): t = Timer(proper_divisors_sum1(50), from __main__ import proper_divisors_sum) print round(t.timeit(number=1),3) Thanks, Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Building input for a function call
Hey Buddy Pals, In the below *function*(if you can call it that yet:) I'm trying to do the following: interpolate this string: 'OptionMenu(self.frame,self.var,'%s','%s')' with this list turned into variables: ['default1', 'default2'] which would become: self.default1 = 'default1' self.default2 = 'default2' So that I have: OptionMenu(self.frame,self.var,self.default1,self.default2) or even: OptionMenu(self.frame,self.var,'default1','default2') Starting from the top: from self.obtup I obtain a tuple: (7, 8) I then use the tuple to identify an object the numbers in self.obtup represent, and build a list from this in self.list: ['default1', 'default2'] I then build a string for a later to be used menu with: self.string = 'OptionMenu(self.frame,self.var' + str(self.listlen * ',%s') + ')' which gives: self.string = OptionMenu(self.frame,self.var,%s,%s) And then build a variable list self.list2 = ['self.default1 = ', 'self.default2 = '] So that I have: self.default1 = self.default2 = Then append to those the variables they represent so that I have self.default1 = 'default1' self.default2 = 'default2' When I get to the step above, trying to use eval()(the data is restricted to variable names, but I know a misnamed with a invalid character could cause problems) in a loop, so that it uses the combined as a variable, but get an error for the '='. I've tried several different methods this seemed like the best course, but maybe not. *Note files self.f1 and self.f2 are temporary holders for: OptionMenu(self.frame,self.var,'%s','%s') = where the %s's should be replaced with the vars or strings. and self.f2 is 'self.default1 = ', 'self.default2 = ' Which could probably be handled a better way than a file. @trace def obOpMenu(self): import time self.oblist = self.canvas.find_withtag('object') print self.oblist self.list = [] for item in self.oblist: self.itemname = self.canvas.gettags(item) if self.itemname[1] != 'default': self.list.append(self.itemname[1]) print self.list self.f1 = open('/home/david/pythonfiles/pythonscripts/roughdraftapps/kubit_kaaba/obmenu.txt','w') self.f2 = open('/home/david/pythonfiles/pythonscripts/roughdraftapps/kubit_kaaba/obmenuvar.txt','w') self.listlen = len(self.list) self.string = 'OptionMenu(self.frame,self.var' + str(self.listlen * ,'%s') + ')' self.list2 = [] for line in self.list: self.list2.append('self.%s = ' % (line)) print self.string, self.list2 self.count = 0 for num in range(len(self.list)): print self.list2[num] self.f2.write(str(self.list2).strip('[]')) self.f2.close() #time.sleep(1) #self.f2 = open('/home/david/pythonfiles/pythonscripts/roughdraftapps/kubit_kaaba/obmenuvar.txt','r') #self.f1.write(self.string % self.list2) self.f1.close() #time.sleep(1) #self.f1 = open('/home/david/pythonfiles/pythonscripts/roughdraftapps/kubit_kaaba/obmenu.txt','r') ''' #if len(str(self.oblist)) 2: for field in self.f1.read(): self.abc = q.strip().split( , ) #self.var = StringVar(root) #self.var.set(self.list[0]) #self.optionmenu = self.f1.read() #self.optionmenu.grid(row = 1,column = 2) ''' Thanks, David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
repeatedly, returning a list of results. ... I'm sorry, Steven, but I could you revise this code to use repeat=5 instead of the for loop? I can't see how to do it. help(timeit.Timer repeat(self, repeat=3, number=100) | Call timeit() a few times. | | This is a convenience function that calls the timeit() | repeatedly, returning a list of results. The first argument | specifies how many times to call timeit(), defaulting to 3; | the second argument specifies the timer argument, defaulting | to one million. | | Note: it's tempting to calculate mean and standard deviation | from the result vector and report these. However, this is not | very useful. In a typical case, the lowest value gives a | lower bound for how fast your machine can run the given code | snippet; higher values in the result vector are typically not | caused by variability in Python's speed, but by other | processes interfering with your timing accuracy. So the min() | of the result is probably the only number you should be | interested in. After that, you should look at the entire | vector and apply common sense rather than statistics. if __name__=='__main__': from timeit import Timer for y in range(5): t = Timer(proper_divisors_sum1(50), from __main__ import proper_divisors_sum) print round(t.timeit(number=1),3) Thanks, Dick ___ Tutor maillist - tu...@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] Building input for a function call
Apologies, forgot to add I'm using 2.6.4 on ubuntu 9.10 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] variables question.
Steven D'Aprano, et al, Thanks everyone for the thorough explanations on variable use and scope in Python. It was enlightening...and sometimes confusing, but I'm working on that. It just points out all the new things I have yet to learn about the language. -- ¤¤ ¤ kyoboku kazeoshi ¤ ¤¤ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
On Fri, Nov 12, 2010 at 05:15, David Hutto smokefl...@gmail.com wrote: repeatedly, returning a list of results. ... I'm sorry, Steven, but I could you revise this code to use repeat=5 instead of the for loop? I can't see how to do it. help(timeit.Timer repeat(self, repeat=3, number=100) | Call timeit() a few times. | | This is a convenience function that calls the timeit() | repeatedly, returning a list of results. The first argument | specifies how many times to call timeit(), defaulting to 3; | the second argument specifies the timer argument, defaulting | to one million. | | Note: it's tempting to calculate mean and standard deviation | from the result vector and report these. However, this is not | very useful. In a typical case, the lowest value gives a | lower bound for how fast your machine can run the given code | snippet; higher values in the result vector are typically not | caused by variability in Python's speed, but by other | processes interfering with your timing accuracy. So the min() | of the result is probably the only number you should be | interested in. After that, you should look at the entire | vector and apply common sense rather than statistics. Look, I've already shown I know where the docs are, and have read them. I don't understand how to use repeat() with my code. Wasn't that clear to you? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 35
Hello tutor i want to thnak you for that efort but it's enough . I no longer want you messages a bout python sorry .The reason is my conputer is infected with alot of TROJANs and WORMS , VIRUSES,SPYWARES and all to me comes from you poeple so i just want to a void you. I will learn python through the PDF i Read and the Google python class vidoe than you viruses destroying my PC I NO LONGER WANT YOU MESSAGES DON'T REPLY ME ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
Apologies, missed that part. Didn't mean to seem rude. import timeit def anyName(): pass for num in range(10): t = timeit.Timer('anyName()','from __main__ import anyName') print t.repeat(repeat=5) #or import timeit def anyName(): pass t = timeit.Timer('anyName()','from __main__ import anyName') print t.repeat(repeat=5) If I get the gist of what you're asking. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 35
Wangolo Joel, 12.11.2010 15:45: I NO LONGER WANT YOU MESSAGES DON'T REPLY ME Nice try. Stefan PS: You can unsubscribe at any time by following the instructions on the mailing list web site. See the footer of any message sent to this list. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 35
Hi Joel, To start with, I sincerely appreciate your concern and I am deeply sorry your computer is so infected. Having said that, I think it is unfair to pile all the blames and as a matter of fact, any at all, on this group. That is very unfair to say the least. I don't have an idea of how long you have been on this mailing list but I am quite sure you are not the first to subscribe and you can't be the last. It therefore bothers me that you are the onlt person I have heard say such a terrible thing about this group despite all measures in place to avoid sending malicious elements. I hope you are aware this group doesn't allow attachments except you are suggesting the viruses you are talking about are the letters and numerals in the mails. That then underscores your knowledge as an IT person. Second, you had an option to stick with your PDF and google stuff before coming on this mailing list. If you are all of a sudden attached to your PDF again, it ia matured enough to unsubscribe and be thankful for the things you have learnt in here. While I hope you would have a change of mind and apologise for your very harsh and false accusations, I hope you would also understand that everybody here despite our different backgrounds have gone thus far because we play by the rules and we are interested in not only learning python but teaching too and making everyone smile. Have a great day. Regards Sent from my BlackBerry wireless device from MTN -Original Message- From: Wangolo Joel wango...@yahoo.com Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 12 Nov 2010 14:45:21 To: tutor@python.org Subject: Re: [Tutor] Tutor Digest, Vol 81, Issue 35 ___ 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] List comprehension question
On Fri, Nov 12, 2010 at 07:13, David Hutto smokefl...@gmail.com wrote: import timeit def anyName(): pass t = timeit.Timer('anyName()','from __main__ import anyName') print t.repeat(repeat=5) If I get the gist of what you're asking. Yes. That's it! Thank you! And if I don't want the default number of 1 million, I can use print t.repeat(repeat=5,number=3000) See http://tutoree7.pastebin.com/fUVs8CBj where I compare speeds of 2 functions. Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 81, Issue 35
Hi - I just wanted to comment that my Windows XP system hasn't found any threats like this coming from the Python list emails. I also have a netbook with Windows 7 Starter and no problems there either. I am using AVG 9.0.869 on both systems which is *Great* for security and if a threat is found, it will give you the email with just the header and a note in the body that AVG didn't allow the message through because it detected a virus or malicious something or other. Patty - Original Message - From: delegb...@dudupay.com To: tutor tutor@python.org Sent: Friday, November 12, 2010 7:05 AM Subject: Re: [Tutor] Tutor Digest, Vol 81, Issue 35 Hi Joel, To start with, I sincerely appreciate your concern and I am deeply sorry your computer is so infected. Having said that, I think it is unfair to pile all the blames and as a matter of fact, any at all, on this group. That is very unfair to say the least. I don't have an idea of how long you have been on this mailing list but I am quite sure you are not the first to subscribe and you can't be the last. It therefore bothers me that you are the onlt person I have heard say such a terrible thing about this group despite all measures in place to avoid sending malicious elements. I hope you are aware this group doesn't allow attachments except you are suggesting the viruses you are talking about are the letters and numerals in the mails. That then underscores your knowledge as an IT person. Second, you had an option to stick with your PDF and google stuff before coming on this mailing list. If you are all of a sudden attached to your PDF again, it ia matured enough to unsubscribe and be thankful for the things you have learnt in here. While I hope you would have a change of mind and apologise for your very harsh and false accusations, I hope you would also understand that everybody here despite our different backgrounds have gone thus far because we play by the rules and we are interested in not only learning python but teaching too and making everyone smile. Have a great day. Regards Sent from my BlackBerry wireless device from MTN -Original Message- From: Wangolo Joel wango...@yahoo.com Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 12 Nov 2010 14:45:21 To: tutor@python.org Subject: Re: [Tutor] Tutor Digest, Vol 81, Issue 35 ___ 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Building input for a function call
This is a more precise question, the above was after trying different methods, and it got a little confusing. Why in the below does using in line 12:self.objectsvars = 'menuitemhere','menuitemhere','menuitemhere','menuitemhere', not work, but placing 'menuitemhere','menuitemhere','menuitemhere','menuitemhere' in line 17 directly work? def obOpMenu(self): print 'Dummy' #This is my tony robins help import time self.oblist = self.canvas.find_withtag('object') print self.oblist self.list = [] for item in self.oblist: self.itemname = self.canvas.gettags(item) if self.itemname[1] != 'default': self.list.append(self.itemname[1]) print self.list self.objectsvars = 'menuitemhere','menuitemhere','menuitemhere','menuitemhere' print type(self.objectsvars[0]) self.var = StringVar(self.root) self.var.set(self.objectsvars[0]) self.optionmenu = OptionMenu(self.frame,self.var,self.objectsvars) self.optionmenu.grid(row = 1,column = 2) Hope that's clearer:) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Building input for a function call
This is a more precise question, the above was after trying different methods, and it got a little confusing. Why in the below does using in line 12:self.objectsvars = 'menuitemhere','menuitemhere','menuitemhere','menuitemhere', not work, but placing 'menuitemhere','menuitemhere','menuitemhere','menuitemhere' in line 17 directly work? Singled out the two lines for clarity: 12: self.objectsvars = 'menuitemhere','menuitemhere','menuitemhere','menuitemhere' 17: self.optionmenu = OptionMenu(self.frame,self.var,self.objectsvars) Because in the first case, you're passing 3 items to OptionMene: self.frame, self.var a tuple. The tuple itself contains four items, but it is still a single item as passed to OptionMenu. In the second case, you're passing 6 items total. If you want to use self.objectsvars, using the asterisk notation to expand your list or tuple: OptionMenu(self.frame, self.var, *self.objectsvars) Though I believe (haven't tried) that that actually doesn't work (depending on how OptionMenu.__init_ is defined), and you may need to pack everything into a single tuple, and expand that: OptionMenu( *((self.frame, self.var) + self.objects)) So in that case, I'm adding a 2-tuple and a 4-tuple, and then expanding that. I need extra parentheses, otherwise only the 2-tuple gets expanded. Which of the above two cases you need, depends on how OptionMenu.__init__ is declared: def __init__(self, frame, var, *args) should allow for the first, while def __init__(self, *args) will work in the second case, since frame and var aren't picked up separately when calling the function. Google and read around for 'Python args kwargs', if this went somewhat over your head. Or just try and play with it some more. Cheers, Evert def obOpMenu(self): print 'Dummy' #This is my tony robins help import time self.oblist = self.canvas.find_withtag('object') print self.oblist self.list = [] for item in self.oblist: self.itemname = self.canvas.gettags(item) if self.itemname[1] != 'default': self.list.append(self.itemname[1]) print self.list self.objectsvars = 'menuitemhere','menuitemhere','menuitemhere','menuitemhere' print type(self.objectsvars[0]) self.var = StringVar(self.root) self.var.set(self.objectsvars[0]) self.optionmenu = OptionMenu(self.frame,self.var,self.objectsvars) self.optionmenu.grid(row = 1,column = 2) Hope that's clearer:) ___ 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
[Tutor] 'pydoc' is not recognized as an internal or external command, ...
Hello All, I'm currently attempting to work my way through Zed Shaw's Learn Python the Hard Way (suggested by co-workers) and have come across an instruction to: 1. In Terminal where you normally run python to run your scripts, type: pydoc raw_input. Read what it says. So in a terminal, at the command prompt I type: pydoc raw_input. I'm going out on a limb here - I don't believe the following is what I was supposed to read: 'pydoc' is not recognized as an internal or external command, operable program or batch file. The word pydoc is in single quotes. So, I go back to the terminal and type: python Then I type: pydoc raw_input The computer spits back: File stdin, line1 pydoc raw_input SyntaxError: invalid syntax (There is a carrot symbol under the t of input.) What I've done so far to figure it out: 1. Searching Google and here on the tutor mailing list. I cannot find this exact same phrase - there are many similar ones on the two pages of returned search results, but not the exact same phrase. I assume from the verbiage that I don't have something installed or I have installed something incorrectly but what exactly I cannot tell. 2. Searching this page: http://docs.python.org/library/pydoc.html This page contains lots of great information if you already know what you are doing but not information for how to start or troubleshoot pydoc. For one as new as myself this might as well be in a dead language that has no Rosetta Stone. 3. Picked the brains of the co-workers who recommended the book - they are as confused as me as to why it's not working. They don't seem to have needed it. Any suggestions? Thank you, R. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'pydoc' is not recognized as an internal or external command, ...
For what you're looking for you could use: help(raw_input) In the python terminal,meaning type python first. For pydoc on ubuntu in the command line, pydoc -p 1234 and then take your browser to http://localhost:1234, you might need to select the work offline mode. On windows IIRC it's about the same. I can check if you need it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Building input for a function call
Singled out the two lines for clarity: 12: self.objectsvars = 'menuitemhere','menuitemhere','menuitemhere','menuitemhere' 17: self.optionmenu = OptionMenu(self.frame,self.var,self.objectsvars) Because in the first case, you're passing 3 items to OptionMene: self.frame, self.var a tuple. The tuple itself contains four items, but it is still a single item as passed to OptionMenu. I found out it was a tuple after I posted, which is why the error. It becomes OptionMenu(self.frame,self.var, ('menuitemhere' , 'menuitemhere' , 'menuitemhere' , 'menuitemhere')) This is how it's supposed to be init'd: OptionMenu(self.frame,self.var, 'menuitemhere' , 'menuitemhere' , 'menuitemhere' , 'menuitemhere') Where the args are a series of single strings, the first two are self.frame(which is the parentframe and self.var(which is a starting reference for the menu) In the second case, you're passing 6 items total. It can be as many as I need, in the first email I was trying to state that I have a list of random length that has to be placed into those end values as args. If you want to use self.objectsvars, using the asterisk notation to expand your list or tuple: OptionMenu(self.frame, self.var, *self.objectsvars) by expand, do you mean remove the tuple value, and leave the contents(I'll try either way) Though I believe (haven't tried) that that actually doesn't work (depending on how OptionMenu.__init_ is defined), and you may need to pack everything into a single tuple, and expand that: OptionMenu( *((self.frame, self.var) + self.objects)) So in that case, I'm adding a 2-tuple and a 4-tuple, and then expanding that. I need extra parentheses, otherwise only the 2-tuple gets expanded. In think this would work in the apply() method I tried, which took a tuple argument, but I didn't need backward compatability, so I was using the function outright. Again I'll see if that will work. Which of the above two cases you need, depends on how OptionMenu.__init__ is declared: def __init__(self, frame, var, *args) should allow for the first, while def __init__(self, *args) will work in the second case, since frame and var aren't picked up separately when calling the function. Google and read around for 'Python args kwargs', if this went somewhat over your head. Or just try and play with it some more. Probably both, but I don't think that's the appropriate search term I need at this point. This is my current revision which writes a python file then calls the function, but not quite right yet: def obOpMenu(self): print 'Dummy' #This is my tony robins help self.oblist = self.canvas.find_withtag('object') print self.oblist self.list = [] for item in self.oblist: self.itemname = self.canvas.gettags(item) if self.itemname[1] != 'default': self.list.append(self.itemname[1]) print self.list self.objectsvars = str(self.list).strip('[]') print self.objectsvars self.listlen = len(self.list) self.var = StringVar(self.root) self.var.set(self.objectsvars[0]) self.f1 = open('/home/david/pythonfiles/pythonscripts/roughdraftapps/kubit_kaaba/other.py','w') self.f1.write(from Tkinter import * def thisDef(frame,var): optionmenu = OptionMenu(frame,var,%s) return optionmenu % (str(self.list).strip('[]'))) self.f1.close() self.optionmenu = thisDef(self.frame,self.var) print self.optionmenu,'*' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Building input for a function call
Fixed with: def obOpMenu(self): self.oblist = self.canvas.find_withtag('object') self.list = [] for item in self.oblist: self.itemname = self.canvas.gettags(item) if self.itemname[1] != 'default': self.list.append(self.itemname[1]) self.objectsvars = str(self.list).strip('[]') self.var = StringVar(self.root) self.var.set(self.objectsvars[0]) self.f1 = open('/home/david/pythonfiles/pythonscripts/roughdraftapps/kubit_kaaba/other.py','w') self.f1.write(from Tkinter import * def thisDef(frame,var): optionmenu = OptionMenu(frame,var,%s) optionmenu.grid(row = 1,column = 2) return optionmenu % (str(self.list).strip('[]'))) self.f1.close() from other import * self.optionmenu = thisDef(self.frame,self.var) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
Richard D. Moores wrote: OK, but why can't I do what the timeit doc suggests, only put 2 or more functions in the file, as I do here: http://tutoree7.pastebin.com/84u1fkgA def test(): Stupid test function L = [] for i in range(100): L.append(i) if __name__=='__main__': from timeit import Timer t = Timer(test(), from __main__ import test) print t.timeit() There's nothing wrong with that, except that running the test *once* (as you do) is subject to greater chance fluctuations than running it multiple times: change the last line to: print min(t.repeat()) Note that you don't *have* to do this, the world will not end if you don't, but your timing results will be just a little more accurate if you do. If you want to time multiple functions, just use multiple timer objects: t1 = Timer(test(), from __main__ import test) t2 = Timer(spam(), from module import spam) t3 = Timer(ham(), from module import ham) I'm sorry, Steven, but I could you revise this code to use repeat=5 instead of the for loop? I can't see how to do it. You don't need to choose repeat=5. The default is 3, but you can specify any number you like. I just like 5 :) if __name__=='__main__': from timeit import Timer for y in range(5): t = Timer(proper_divisors_sum1(50), from __main__ import proper_divisors_sum) print round(t.timeit(number=1),3) if __name__=='__main__': from timeit import Timer t = Timer(proper_divisors_sum(50), from __main__ import proper_divisors_sum) best = t.repeat(number=1, repeat=5) print round(best, 3) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'pydoc' is not recognized as an internal or external command, ...
R Johnson wrote: 'pydoc' is not recognized as an internal or external command, operable program or batch file. This means that the program pydoc is not installed on your computer, or is installed somewhere where the operating system (I'm guessing you're using Windows?) can't find it. Use the Find File command, and see if you can find something called pydoc. You may need to call the full path to the program, e.g.: C:\My Documents\path\to\program\pydoc raw_input or you may need to install it :) So, I go back to the terminal and type: python Then I type: pydoc raw_input The computer spits back: File stdin, line1 pydoc raw_input SyntaxError: invalid syntax (There is a carrot symbol under the t of input.) pydoc is an external tool made with Python, it is not a Python command you can run. However, Python does come with an internal tool that is nearly as powerful: help(). From the Python prompt, type: help(raw_input) and Enter, and you will get something very close to what pydoc would have given you. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'pydoc' is not recognized as an internal or external command, ...
On Fri, Nov 12, 2010 at 6:44 PM, Steven D'Aprano st...@pearwood.info wrote: Use the Find File command, and see if you can find something called pydoc. You may need to call the full path to the program, e.g.: C:\My Documents\path\to\program\pydoc raw_input On my windows PC, it's c:\Python31\Lib\pydoc.py So, to do what the tutorial is suggesting, you would need to open a command prompt (cmd.exe) and run: c:\Python31\Lib\pydoc.py raw_input Note: Since I have python 3.1 installed, that wouldn't actually work, because python 3.1 no longer has a raw_input function -- it's been renamed to just input. If you want to be able to run pydoc.py without specifying the full path every time, I could add C:\Python31\Lib to my PATH environment variable. -- Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python 2.5 Problem
Patrick Forbes wrote: I was pointed towards ignoblekey/pub pyw's and couldn't figure out to work them. I was told to use Python 2.6 but couldn't find it as I was unaware it was buried in the Library and didn't know how to work Terminal. I made several boo boo's and lost the Python 2.5 that my Mac once had and tried to get 2.7 installed. Was informed 2.5 was the better choice. 2.7 didn't put its stuff where it was supposed to be and when I found 2.5, it's installation failed: This mailing list is for help in learning the programming language Python. You would be better off asking for help on some Apple Macintosh forum: I've accidentally trashed the system Python 2.5, how do I reinstall it? How do I install Python 2.6 or 2.7 without trashing the system Python? You'll need to mention what version of Mac OS you're running. If the Mac forum can't help, the general purpose Python forum might have some Mac users who can help. Try the python-l...@python.org mailing list, or if you prefer Usenet, comp.lang.python. Good luck! -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is a state variable?
Richard D. Moores rdmoo...@gmail.com wrote For example if I say that the state of any object can be represented by a vector whose values correspond to the collected set of variables of the object, does that make sense? No. Not the vector idea. Sorry. A vector is just a fancy mathematical name for an array of values. In the case of state the values are those of the set of relevant variables that control the behaviour of the program. In the case of an object it is usually the set of attributes of the object plus any local/environment variables. (An object can be thought of as a container in the same way as a list or dictionary) So the state variables of a class are those that affect the functioning of the class. As an example we might have a simple traffic light that cycles through the 3 states (green, amber red) at a set time interval. The only state variable is likely to be one holding the current state name. But we could make it more complex by having the traffic light interval controlled by traffic density based on a count of the number of cars passing during a green phase. Now we have two factors controlling the state change - the old value and the counter - two state variables. We then might introduce different intervals per state change - so we get a set of 4 timer values - now 6 state variables. And so on. We might also have some other variables that are purely data such as the location of the light, or the date of installation. But these may have no effect on the function of the light. These are attributes but they are not state variables - they don't affect the state. Of course, in practice they may affect the state of other operations, like a scheduled cleaning operation - in which case they become state variables but in a different state vector since the cleaning state machine is separate from the lighting state machine. State machines are very important in software engineering, particularly for safety critical systems as they are one of the few specification and design techniques in CS that are both mathematically rigorous, have provably correct implementations and are practical to build.(usually by building a dispatch table of states and their events) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Grabbing Information from txt files
My apologies for my last email, admittedly I was more tired that I thought as after re-reading it and the emails coming in, I found that I did not provided proper information. 1. I have a script that is detecting multiple various bits of information of a video file using MediaInfo and putting that information into a txt file with the format of: (Example:) num_vid_track=? num_aud_track=? num_sub_track=? Granted that is only part of the information being obtained but it's all in the same format. I have been trying multiple ways of grabbing this information for re-use, including using this snippet, suggested to me by fellow users of the #python irc channel.. import shlex as shlex_ from subprocess import Popen, PIPE def shell(args, input=None, stdout=PIPE, stderr=PIPE, shlex=False, **kwargs): Gets the output of a command run in a subprocess. Arguments: args: A sequence of strings, or a single string if shlex=True. input: A string to be written to the process's stdin. Any extra keyword arguments are forwarded to Popen. Returns: A tuple of (stdout, stderr) shell('basename /a/hello', shlex=True) ('hello\n','') if shlex: args = shlex_.split(args) stdin = PIPE if input is not None else None p = Popen(args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs) return p.communicate(input=input) Then using a command line similar to: p = subprocess.Popen(['foo', 'bar'], stdout=subprocess.PIPE); stdout, _ = p.communicate() Where 'foo','bar' obviously is the program I am calling with its arguements. The only issue is, I can barely understand the documentation I kept getting pointed to for retrieving the information captured from stdout. Which is why I went with another friends suggestion of outputting all of the information to a text file. Sorry if this seems to have veered off course, but which method would be more recommended to implement? So far I have been able to write a different python script for a general conversion of videos from multiple different formats to a single format my xbox 360 can read (with or without is optional media update). Again sorry for my previous email, and thank you in advance for the assistance and suggestions, Mike ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'pydoc' is not recognized as an internal or external command, ...
Thank you to all who have responded. I have a bit of an update that reflects some of these suggestions. I was able to snag some time from one of the more experienced engineers and here is what we found: On my system (Windows 7) the path to the lib file is C:\Python26\lib and pydoc.py is in this folder. So, he had me run: python -m pydoc raw_input at that prompt. Sure enough, this returned what looked like help information for raw_input. And, when we he had me follow the trail: Start Control Panel System Advanced Settings Environment Variables Python26 was in the PATH. From: Steven D'Aprano st...@pearwood.info To: tutor@python.org Sent: Fri, November 12, 2010 5:44:41 PM Subject: Re: [Tutor] 'pydoc' is not recognized as an internal or external command, ... R Johnson wrote: 'pydoc' is not recognized as an internal or external command, operable program or batch file. This means that the program pydoc is not installed on your computer, or is installed somewhere where the operating system (I'm guessing you're using Windows?) can't find it. Use the Find File command, and see if you can find something called pydoc. You may need to call the full path to the program, e.g.: C:\My Documents\path\to\program\pydoc raw_input or you may need to install it :) So, I go back to the terminal and type: python Then I type: pydoc raw_input The computer spits back: File stdin, line1 pydoc raw_input SyntaxError: invalid syntax (There is a carrot symbol under the t of input.) pydoc is an external tool made with Python, it is not a Python command you can run. However, Python does come with an internal tool that is nearly as powerful: help(). From the Python prompt, type: help(raw_input) and Enter, and you will get something very close to what pydoc would have given you. -- Steven ___ 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] Grabbing Information from txt files
Random thoughts: 1.) Maybe you should be looking at something like Fuppes instead: http://fuppes.ulrich-voelkel.de/ ? 2.) Even so, continuing with your current direction: there appears to be a module/wrapper of MediaInfo for Python, thus removing the need to scrape information from MediaInfo's output, which is what I presume you're trying to do above. Might be useful. See here: http://forum.doom9.org/showthread.php?t=96516page=11 Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Grabbing Information from txt files
On Fri, Nov 12, 2010 at 9:43 PM, Michael Stover m_stover4381...@yahoo.com wrote: My apologies for my last email, admittedly I was more tired that I thought as after re-reading it and the emails coming in, I found that I did not provided proper information. 1. I have a script that is detecting multiple various bits of information of a video file using MediaInfo and putting that information into a txt file with the format of: (Example:) num_vid_track=? num_aud_track=? num_sub_track=? Granted that is only part of the information being obtained but it's all in the same format. I have been trying multiple ways of grabbing this information for re-use, including using this snippet, suggested to me by fellow users of the #python irc channel.. import shlex as shlex_ from subprocess import Popen, PIPE def shell(args, input=None, stdout=PIPE, stderr=PIPE, shlex=False, **kwargs): Gets the output of a command run in a subprocess. Arguments: args: A sequence of strings, or a single string if shlex=True. input: A string to be written to the process's stdin. Any extra keyword arguments are forwarded to Popen. Returns: A tuple of (stdout, stderr) shell('basename /a/hello', shlex=True) ('hello\n','') if shlex: args = shlex_.split(args) stdin = PIPE if input is not None else None p = Popen(args, stdin=stdin, stdout=stdout, stderr=stderr, **kwargs) return p.communicate(input=input) Then using a command line similar to: p = subprocess.Popen(['foo', 'bar'], stdout=subprocess.PIPE); stdout, _ = p.communicate() Where 'foo','bar' obviously is the program I am calling with its arguements. The only issue is, I can barely understand the documentation I kept getting pointed to for retrieving the information captured from stdout. Which is why I went with another friends suggestion of outputting all of the information to a text file. Sorry if this seems to have veered off course, but which method would be more recommended to implement? So far I have been able to write a different python script for a general conversion of videos from multiple different formats to a single format my xbox 360 can read (with or without is optional media update). Again sorry for my previous email, and thank you in advance for the assistance and suggestions, Mike ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor It'll alll become clear soon danielson/grasshoppa. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Grabbing Information from txt files
Random thoughts: 1.) Maybe you should be looking at something like Fuppes instead: http://fuppes.ulrich-voelkel.de/ ? 2.) Even so, continuing with your current direction: there appears to be a module/wrapper of MediaInfo for Python, thus removing the need to scrape information from MediaInfo's output, which is what I presume you're trying to do above. Might be useful. See here: http://forum.doom9.org/showthread.php?t=96516page=11 Walter I didn't get Fruppes in any of my original searches, I will give that a try, and I have tried the module/wrapper for MediaInfo but have to wait for a bug fix as it does not work correctly with 64bit Linux. At least not with Python 2.6, and I am reluctant to upgrade to Python 3 due to compatibility issues. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What is a state variable?
On Fri, Nov 12, 2010 at 17:07, Alan Gauld alan.ga...@btinternet.com wrote: Richard D. Moores rdmoo...@gmail.com wrote For example if I say that the state of any object can be represented by a vector whose values correspond to the collected set of variables of the object, does that make sense? I think I would have understood this if you have used array of values instead of vector. No. Not the vector idea. Sorry. A vector is just a fancy mathematical name for an array of values. In the case of state the values are those of the set of relevant variables that control the behaviour of the program. In the case of an object it is usually the set of attributes of the object plus any local/environment variables. (An object can be thought of as a container in the same way as a list or dictionary) So the state variables of a class are those that affect the functioning of the class. As an example Your increasingly complex but clear example was very useful to me. Thank you. Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Grabbing Information from txt files
Michael Stover wrote: My apologies for my last email, admittedly I was more tired that I thought as after re-reading it and the emails coming in, I found that I did not provided proper information. 1. I have a script that is detecting multiple various bits of information of a video file using MediaInfo and putting that information into a txt file with the format of: (Example:) num_vid_track=? num_aud_track=? num_sub_track=? Granted that is only part of the information being obtained but it's all in the same format. I have been trying multiple ways of grabbing this information for re-use, including using this snippet, suggested to me by fellow users of the #python irc channel.. [snip] only issue is, I can barely understand the documentation I kept getting pointed to for retrieving the information captured from stdout. Which is why I went with another friends suggestion of outputting all of the information to a text file. Sorry if this seems to have veered off course, but which method would be more recommended to implement? There's absolutely nothing wrong with an assembly line of components: Use MediaInfo to write data to a text file; Use Python to read the text file and process it; Use some tool to modify the video according to the text file; etc. You don't need a single monolithic script to do everything... if you have an easy way of calling MediaInfo and getting it to write its data to text files, stick with that. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
On Fri, Nov 12, 2010 at 15:26, Steven D'Aprano st...@pearwood.info wrote: Richard D. Moores wrote: OK, but why can't I do what the timeit doc suggests, only put 2 or more functions in the file, as I do here: http://tutoree7.pastebin.com/84u1fkgA def test(): Stupid test function L = [] for i in range(100): L.append(i) if __name__=='__main__': from timeit import Timer t = Timer(test(), from __main__ import test) print t.timeit() There's nothing wrong with that, except that running the test *once* (as you do) is subject to greater chance fluctuations than running it multiple times: change the last line to: print min(t.repeat()) Note that you don't *have* to do this, the world will not end if you don't, but your timing results will be just a little more accurate if you do. If you want to time multiple functions, just use multiple timer objects: t1 = Timer(test(), from __main__ import test) t2 = Timer(spam(), from module import spam) t3 = Timer(ham(), from module import ham) I'm sorry, Steven, but could you revise this code to use repeat=5 instead of the for loop? I can't see how to do it. You don't need to choose repeat=5. The default is 3, but you can specify any number you like. I just like 5 :) So I'll go with your 5. if __name__=='__main__': from timeit import Timer for y in range(5): t = Timer(proper_divisors_sum1(50), from __main__ import proper_divisors_sum) print round(t.timeit(number=1),3) if __name__=='__main__': from timeit import Timer t = Timer(proper_divisors_sum(50), from __main__ import proper_divisors_sum) best = t.repeat(number=1, repeat=5) print round(best, 3) t.repeat(number=1, repeat=5) is a list of the 5 times, not the best of the 5. So I used min(t.repeat(number=1, repeat=5)) See http://tutoree7.pastebin.com/ Thanks very much, Steven! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehension question
On Fri, Nov 12, 2010 at 23:25, Richard D. Moores rdmoo...@gmail.com wrote: See http://tutoree7.pastebin.com/ Sorry, forgot to paste. http://tutoree7.pastebin.com/CYAm8arG Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor