Re: [Tutor] how to run a text file in an interpreter?
Hi Tonu, Tonu Mikk wrote: > I do not know what the author means by running a text file with the > interpreter. I noticed that I came across an obstacle early on in trying > out the code. What plattform are you in? Linux, Windows, Mac? Check out the faqs at: http://www.python.org/doc/faq/windows/#how-do-i-run-a-python-program-under-windows ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line args
Teresa Stanton wrote: > If one argument to a script is provided I am to take the input from it. > I figure that is presented like this: > > filename = sys.argv[1] Try: filename=sys.arg[1] except exception, E: filename='FooBar' > data = open(filename).read() > > But, if none are provided, input should come from standard input. How > do I write that code? > > TY > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 269.0.0/750 - Release Date: 4/6/2007 9:30 > PM -- Salute! -Kirk Bailey Think +-+ | BOX | +-+ knihT Fnord. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fw: 2) 'WHICH MULTI'
"Terry Carroll" <[EMAIL PROTECTED]> wrote >> One of my tutorial users has come upon a really weird bug. >> >> He has sent a transcript oif his session. Notice that wx >> is not defined yet doing help(wx) produces a strange message. > > Very weird. Here's what I get, weird in a different way... Just for completeness... I don't know what caused Terry's problem but the guy who wrote to me solved his problem. He had a rogue file new.pyc without a corresponding new.py. I still don't understand how that got picked up by help() but deleting the rogue file made the problem go away... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Addressing a variable whose name is the value of a string
John Clark wrote: > locals()[var] > > But I am not sure what the pros/cons for doing something like this would > be... locals() should be considered read-only. From the docs: locals( ) Update and return a dictionary representing the current local symbol table. Warning: The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter. At global scope, locals() == globals() and modifying locals() will work. Within a function, modifying locals() will not do what you want. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Addressing a variable whose name is the value of a string
Andreas Pfrengle wrote: > Bob Gailer wrote: >>> Now I want to change the value of x, but address it via var. >> exec is the statement for doing this, but the need to do this can >> always be met better by using a dictionary instead of global variables. >> > Thanks Bob, the 'exec' saved me. But I'm not sure how I could solve my > specific problem with a dict, since my 'var' variable is a string I'm > getting from a database-field, that refers to the name of another field, > which should be changed. So I see no other way than resolving the string > in some instance - or is there? It sounds like your database value is the one that should be stored in a dictionary, or as an attribute of a class instance (which can be changed with setattr()). Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Addressing a variable whose name is the value of a string
Andreas Pfrengle wrote: > [snip] > looks good if I'm happy with my values inside mydict and don't want to > have sth. like x=5 in the end. But since 'x' is the name of a database > field (I simplified it here for an example), I still see no way around > the exec, so I can change the content of the x-field (consider the > content of the var-field as a vector to the corresponding field that > needs a change, x in the example). > If this is still possible with a dict, I still don't see it (sorry), > but it would surely be more elegant than an exec-solution, since I > don't need security checks for the string that is saved, before > executing it. I'd love to help, but am confused. If your code (at least the relevant part) is of reasonable size, would you post it? Or at least some pseudo-code so I can follow your algorithm? -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HTML IN PYTHON AND OTHER DELIGHTS
On 4/8/07, Kirk Bailey <[EMAIL PROTECTED]> wrote: > It works. but when you mouse copy and paste, you get this: [...] This has what to do with Python? -- - Rikard - http://bos.hack.org/cv/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] HTML IN PYTHON AND OTHER DELIGHTS
OK, riddle me this. Using css, I supressed the bullet in unordered lists. The Print line prints an '*' before the item in the listing. so you will see displayed: * abba * abbb * abbc * abbd so the listing can be copied and pasted into a listing in a wiki page. It works. but when you mouse copy and paste, you get this: # * abba # * abbb # * abbc # * abbd which did not display. Intresting. why, and how to overcome this design misfeature? -- Salute! -Kirk Bailey Think +-+ | BOX | +-+ knihT Fnord. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Addressing a variable whose name is the value of a string
Jordan Greenberg wrote: Andreas Pfrengle wrote: Bob Gailer wrote: Andreas Pfrengle wrote: Hello, I want to change the value of a variable whose name I don't know, but this name is stored as a string in another variable, like: x = 1 var = 'x' Now I want to change the value of x, but address it via var. exec is the statement for doing this, but the need to do this can always be met better by using a dictionary instead of global variables. Thanks Bob, the 'exec' saved me. But I'm not sure how I could solve my specific problem with a dict, since my 'var' variable is a string I'm getting from a database-field, that refers to the name of another field, which should be changed. So I see no other way than resolving the string in some instance - or is there? Sure, you do something like: mydict={'x':1, 'y':2} var='x' mydict[var]=5 and then you just access it like mydict['x'] instead of just x. Jordan Hi Jordan, looks good if I'm happy with my values inside mydict and don't want to have sth. like x=5 in the end. But since 'x' is the name of a database field (I simplified it here for an example), I still see no way around the exec, so I can change the content of the x-field (consider the content of the var-field as a vector to the corresponding field that needs a change, x in the example). If this is still possible with a dict, I still don't see it (sorry), but it would surely be more elegant than an exec-solution, since I don't need security checks for the string that is saved, before executing it. Andreas ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Addressing a variable whose name is the value of a string
Bob Gailer wrote: > Andreas Pfrengle wrote: > >> Hello, >> >> I want to change the value of a variable whose name I don't know, but >> this name is stored as a string in another variable, like: >> >> x = 1 >> var = 'x' >> >> Now I want to change the value of x, but address it via var. > > exec is the statement for doing this, but the need to do this can > always be met better by using a dictionary instead of global variables. > Thanks Bob, the 'exec' saved me. But I'm not sure how I could solve my specific problem with a dict, since my 'var' variable is a string I'm getting from a database-field, that refers to the name of another field, which should be changed. So I see no other way than resolving the string in some instance - or is there? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Addressing a variable whose name is the value of a string
Bob Gailer wrote: >Andreas Pfrengle wrote: >> Hello, >> >> I want to change the value of a variable whose name I don't know, but >> this name is stored as a string in another variable, like: >> >> x = 1 >> var = 'x' >> >> Now I want to change the value of x, but address it via var. > >exec is the statement for doing this, but the need to do this can always be met better by using a dictionary instead of global variables. > I think you can also do this with globals()[var] -or- locals()[var] But I am not sure what the pros/cons for doing something like this would be... -jdc ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Addressing a variable whose name is the value of a string
Andreas Pfrengle wrote: > Hello, > > I want to change the value of a variable whose name I don't know, but > this name is stored as a string in another variable, like: > > x = 1 > var = 'x' > > Now I want to change the value of x, but address it via var. exec is the statement for doing this, but the need to do this can always be met better by using a dictionary instead of global variables. -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TCLtutor like python program
Hello everyone, A couple of months ago, I had posted on this list asking about the usefulness of such a program. Something similar to TclTutor (http://www.msen.com/~clif/TclTutor.html) for python. I've spent some time on this and have come up with a crude first version. I'd appreciate if some of the more experienced members of this list could take a quick look at the program and comment on the code and the content of the lessons. I've written 7 lessons till now. The order is roughly based on the standard python tutorial on python.org. I've used Tkinter for the GUI because it's widely available. I've tried to keep all the GUI functionality in a separate module so that I can add (maybe) GTK support later on. The whole thing is available as a tarball from http://nibrahim.net.in/downloads/pydagogue-0.1.tgz I'd really appreciate some comments and feedback on what everyone thinks about the project. Thanks much. -- ~noufal ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Addressing a variable whose name is the value of a string
Hello, I want to change the value of a variable whose name I don't know, but this name is stored as a string in another variable, like: x = 1 var = 'x' Now I want to change the value of x, but address it via var. I'm quite sure I've already seen a solution for this, but right now I don't get it :-( Some help would be appreciated :-) Thanks in advance, Andreas ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Movies from jpg files
Indeed ;) >Python is Cool :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Movies from jpg files
Dear Greg, thanks the link to pymedia. > Maybe PyMedia is what you are looking for: http://www.pymedia.org I looked for it for a while. It is very cool. I made the next short script from one of the samples that make exactly what I wanted. ### import sys, os, glob, Image, time import pymedia.video.vcodec as vcodec def files2Video(files, outFile='out.mpg', outCodec='mpeg1video'): s= Image.open(files[0]) if outCodec== 'mpeg1video': bitrate= 270 else: bitrate= 980 params= { 'type': 0, 'gop_size': 12, 'frame_rate_base': 125, 'max_b_frames': 0, 'width': s.size[0], 'height': s.size[1], 'frame_rate': 2997, 'deinterlace': 0,'bitrate': bitrate, 'id': vcodec.getCodecID(outCodec) } e= vcodec.Encoder(params) fw= open(outFile, 'wb') for ActPic in files: s= Image.open(ActPic) ss= s.tostring() bmpFrame= vcodec.VFrame(vcodec.formats.PIX_FMT_RGB24, s.size, (ss,None,None)) yuvFrame= bmpFrame.convert(vcodec.formats.PIX_FMT_YUV420P) d= e.encode(yuvFrame) fw.write(d.data) fw.close() if __name__== '__main__': files = glob.glob(r'.\test\*.jpg') files.sort(key=lambda f:(os.stat(f).st_mtime, f)) files2Video(files, time.strftime('Cam1_%Y%m%d%H%M.mpg', time.localtime())) [os.remove(f) for f in files] ### Python is Cool :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] reassign
linda.s wrote: > Hi, > I have a list: [2,5,8,0,1,7] > how i can randomly reassign the values to different location in the list? > for example: > Time 1: [5,2,8,0,1,7] > Time 2: [8,0,7,1,5,2] > Have a look at the .shuffle function in the random module. TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] reassign
Hi, I have a list: [2,5,8,0,1,7] how i can randomly reassign the values to different location in the list? for example: Time 1: [5,2,8,0,1,7] Time 2: [8,0,7,1,5,2] Thanks! Linda ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor