[Tutor] Learning to use pygame but running into errors when using examples from websites
Hello,I've been trying to get myself to learn using pygame. I have created some things but I still need help of examples before I can do it myself but I always run into trouble.On this website I saw a lot of great info regarding pygame: http://www.ida.liu.se/~ETE257/timetable/LecturePythonPygame.htmlIn there is an example where you can draw lines with your mouse with the name "Mouse Input" as a header. This one and more of those examples all end up with errors like this:I saved the code of the example as PaintCircles.py, chmod it to 777 and run it.$ ./PaintCircles.pyfrom: can't read /var/mail/pygame.locals ./PaintCircles.py: line 9: class: command not found./PaintCircles.py: line 11: syntax error near unexpected token `('./PaintCircles.py: line 11: ` def __init__(self):'I expect the website uses correct code and I am doing something wrong but can someone tell me what that might be? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] timeout
Hello,With the time module and sleep(60)?http://www.python.org/doc/2.3.5/lib/module-datetime.html sleep( secs) Suspend execution for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal's catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.WimOn 1/16/06, frank h. <[EMAIL PROTECTED] > wrote:Hellohow can I break a loop after a certain amount of time has passed? pseudocode:with timeout of 60sec:while True:passis there a simple way? without resorting to queues etc. (this is a bitover my head)thanks for any insight you might have -frankOn 1/16/06, frank h. <[EMAIL PROTECTED]> wrote:> Hello> how can I break a loop after a certain amount of time has passed? >> pseudocode:>> with timeout of 60sec:>___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] PIL, fonts and making images
I've been using python wih PIL to create some buttons (automatically inside my program). The following code works and creates a PNG 70x70 with the letter 'p' inside.#!/usr/bin/pythonimport os, sysimport Image, ImageFont, ImageDraw image = Image.new('RGBA',(70,70),(0,0,0))ifo = ImageFont.truetype("arial.ttf",24)#ifo = ImageFont.truetype("MARRFONT.TTF",24)draw = ImageDraw.Draw(image)draw.text((0, 0), 'p', font=ifo) image.save('image.png','PNG')I save this program inside a temp dir and copied arial.ttf inside this directory. It works :-)Want I want though is to do this with MARRFONT.TTF. That is a (free) font that has chesspieces inside. (can be downloaded here: http://antraxja-fonts.iweb.pl/pobierz.php?font=3903 )The font works: inside the download there's a DOC that I can open with OO.org and that let's me show the chesspieces (after I copied the font to my fontsdir). If I type a 'p' in arial and then change the font it shows a Pawn. Cool isn't it? :) But when I un-comment the line with this font and save it I get a black square. Can anyone tell me why it doesn't work? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __iter__
danny: my apologies for sending this to your email instead of the list!! (There I was looking at the list going: WTF DOES IT TAKE SO LONG when it hit me...). *cuts in* No I don't :-) With this: class MyListOfNumbers: def __init__(self, data): self.data = data def __iter__(self): return Pointer(self) class Pointer: def __init__(self, numbers): self.numbers = numbers self.offset = 0 def next(self): if self.offset == len(self.numbers.data): raise StopIteration element = self.numbers.data[self.offset] self.offset = self.offset + 1 return element Where/how/when is 'def next(self(:' called? Oh and if someone has some newby tut's on this I'd appreciate it. All I find are not-so-newby-friendly websites regarding to classes :(* Wim > On 1/17/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > > > > On Mon, 16 Jan 2006, Christopher Spears wrote: > > > > > I'm not sure if I understand __iter__. You use it to create an object > > > that iterates through itself using a next menthod ? > > > > Hi Chris, > > > > Yes, that's one application. > > > > > > But __iter__() doesn't necessarily have to return 'self'. For example, > > here's a useless toy class that might help explain what can happen if we > > do so without thinking: > > > > > > class MyListOfNumbers: > > def __init__(self, data): > > self.data = data > > def __iter__(self): > > return Pointer(self) > > > > > > class Pointer: > > def __init__(self, numbers): > > self.numbers = numbers > > self.offset = 0 > > def next(self): > > if self.offset == len(self.numbers.data): > > raise StopIteration > > element = self.numbers.data[self.offset] > > self.offset = self.offset + 1 > > return element > > > > > > Let's see how this might work: > > > > ### > > >>> nums = MyListOfNumbers([0, 1]) > > >>> for x in nums: > > ... for y in nums: > > ... print x, y > > ... > > 0 0 > > 0 1 > > 1 0 > > 1 1 > > ### > > > > > > > > Now imagine what might happen if we didn't return a separate Pointer > > iterator: > > > > > > class MyListOfNumbers2: > > def __init__(self, data): > > self.data = data > > self.offset = 0 > > > > def __iter__(self): > > return self > > > > def next(self): > > if self.offset == len(self.data): > > raise StopIteration > > element = self.data[self.offset] > > self.offset = self.offset + 1 > > return element > > > > > > On a glance, this also looks reasonable: > > > > ## > > >>> nums = MyListOfNumbers2([3, 1, 4, 1, 5]) > > >>> for n in nums: > > ... print n > > ... > > 3 > > 1 > > 4 > > 1 > > 5 > > ## > > > > > > But, of course, you know that there has to be SOMETHING wrong here. > > *grin* > > > > And here's one example that shows a problem: > > > > ## > > >>> nums = MyListOfNumbers2([0, 1]) > > >>> for x in nums: > > ... for y in nums: > > ... print x, y > > ... > > 0 1 > > >>> > > ## > > > > We expected to see all pairs of 0-1 combinations, but came up way short. > > Do you know why? > > > > > > Best of wishes! > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Guess Your Number Game
On 1/17/06, Jon Moore <[EMAIL PROTECTED]> wrote: > Hi > > I hope someone can help me! > > I am currently learning Python using a book by Michael Dawson. In one of the > exercises I have to right a program that will guess a number chosen by the > user. > > It is partly working, however it does not seem to keep state of numbers that > should have already been ruled out as too high or low. > > Any pointers would be very much appreciated! > > import random > > print "Welcome to 'Guess Your Number'!" > print "\nThink of a number between 1 and 100." > print "And I will try and guess it!\n" > print "Valid inputs are: higher, lower and correct." > > raw_input("\n\nPress enter once you have thought of a number.") > > > # set the initial values > guess = random.randrange(100) + 1 > tries = 1 > > > > # guessing loop > response = "" > while response != "correct": > print "Is it" ,guess, "?\n" > response = raw_input ("") > if response == "lower": > guess = random.randrange(1, guess) > elif response == "higher": > guess = random.randrange(guess, 100) > > > # Error message for invalid inputs > else: > print "Invalid entry!" > > > tries += 1 > > > print "\nI guessed it! The number was", guess > print "And it only took me", tries, "tries!\n" > > > raw_input("\n\nPress the enter key to exit.") > > -- > Best Regards > > Jon > > -- > Best Regards > > Jon Moore > sidenote: Hello, 1 thing I spotted: response = raw_input ("") if response == "lower": guess = random.randrange(1, guess) tries += 1 elif response == "higher": guess = random.randrange(guess, 100) tries += 1 # Error message for invalid inputs else: print "Invalid entry!" I myself consider an invalid entry not as a valid try ;) These 2 lines are wrong: > guess = random.randrange(1, guess) > guess = random.randrange(guess, 100) The 1 and 100 are being reset and if the answer WAS lower and is NOW higher you lost your 1st boundary. 1 and 100 should be the previous answer. Regarding your problem: A test needs to be between the highest lowest answer and the lowest highest answer you get. You test between 1 and guess and guess and 100. The 1 and 100 reset your boundary back to the original problem: it needs to be between 1 and 100. number = 40 random = 60 answer lower next test you do is between 1 and guess. new random = 20 answer = higher but now you test between 20 and 100 and NOT between 20 and 60 (<- lowest highest number). ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] escaping spaces in a directoryname
Hmm, a very newby question but I never had to deal with escaping spaces etc.I want to read a directory with spaces in it and it errors out (because of the space).I need to escape it with a \ I guess. I saw alot about that on some websites but they all talk about why and how you escape and not what function can do that. Is there one? Or do I have scan the string and add them myself. *goes back to searching on the web*If I find it before I get an answer I'll post it :=)Wim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [webbrowser] some help on an error running mozilla firefox
Why does this: >>> import webbrowser >>> webbrowser.open('http://www.google.com")give me this: run-mozilla.sh: Cannot execute /opt/firefox/mozilla-firefox-bin. Is this bacause 'webbrowser' does not know about the identification of 1.5?(I do not want to do it like this: >>> import os >>> os.system ('firefox http://www.google.com')bacause not all of us use firefox :) )Oh and can I, when I open a new browserwindow, force it to open in the same workspace as I am with my pythonprogram and not inside another workspace where I have a browser window open? Any enlightment would be appreciated :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] webcam secrets?
That (mosttimes) is a setting in your webcamsoftware and doesn't require coding.WimOn 1/22/06, johnny` walker < [EMAIL PROTECTED]> wrote:i was wondering if there was a way to automatically take a picture from my webcam every oh say 5 minutes? is there anyway of doing this (im very new to programming languages.) ___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Totorial announcement
Excellent guide. I bookmarked it :-) because I plan to use it alot.Oh, how much work (in hours) did it take it to translate your website? WimOn 1/22/06, Alan Gauld <[EMAIL PROTECTED]> wrote: I've just uploaded the completed tutoroial topic on OS access.It covers most of the common questions asked on this list about determiningfile access, launching programs (including use of the new subprocess module),accessing environment variables etc. It also has a short intro to bitmaskmanipulationand bitwise operators.I've also updated the zip, tgz and pdf files too.For those interested in printing out the PDF (someone asked me recently) it currently runs to 342 pages of A4 but the margins are set so it shouldwork fine on US Letter paper too.Enjoy,Alan GAuthor of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Totorial announcement
Saves me ordering the book :-) I saw it on bol.com together with another of your books. Those hours is too much for me otherwise you'd have a Dutch version too :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Totorial announcement
LOL! Did you know I actually thought "wtf and a book about coding and a book about hypnotism? WOW". :D :D :D Well I like books cuz it's easier to carry around inside trains and busses ;) Wim On 1/23/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > Saves me ordering the book :-) > > I saw it on bol.com together with another of your books. > > The book is slightly different and has some extra chapters but it > is now quite out of date, I recommend the web version (which > also has a lot of material not in the book, so swings and > roundabouts there...). > > But I don't have any other books published (yet) the stuff about > hypnotism and psychic stuff is another Alan Gauld based in > Chicago USA - I get a lot of email for him! :-) > > Alan G. > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?
Thank you!*opens manual again*WimOn 1/26/06, Orri Ganel <[EMAIL PROTECTED]> wrote: Rinzwind wrote: In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. I searched on the web for a bit but sgn and sign give me way too many discussions about Decimals. python.org with numbers/digits doesn't tell about a function. Maybe Python uses a different name for it so I am not looking for the correct wording :( Sucks not knowing syntax from my memory and having to look them up alot). Wim ___Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Well, the cmp() function does this if you compare the number to 0: >>> cmp(-34,0) -1 >>> cmp(0,0) 0 >>> cmp(23,0) 1 Of course, that's not all cmp() is good for, but it would work in this case. HTH, Orri -- Email: singingxduck AT gmail DOT comAIM: singingxduckProgramming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?
In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0.I searched on the web for a bit but sgn and sign give me way too many discussions about Decimals. python.org with numbers/digits doesn't tell about a function.Maybe Python uses a different name for it so I am not looking for the correct wording :( Sucks not knowing syntax from my memory and having to look them up alot). Wim ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why can't I find a function that givesme the sign of an integer?
> On 1/26/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > >> In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > > Well, the cmp() function does this if you compare the number to 0: > > Neat trick Orri, I'd never have thought of that one :-) > > Alan G. Glad I could help :=) On 1/26/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Orri Ganel wrote: > > Rinzwind wrote: > > > >> In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > > Well, the cmp() function does this if you compare the number to 0: > > > > >>> cmp(-34,0) > > -1 > > >>> cmp(0,0) > > 0 > > >>> cmp(23,0) > > One caution: this behaviour doesn't seem to be required, the docs allow > any positive or negative integer: > cmp( x, y) > Compare the two objects x and y and return an integer according to > the outcome. The return value is negative if x < y, zero if x == y and > strictly positive if x > y. > > So this behaviour might differ between Python versions. > > Kent Now you lost me. Eh you mean to say that in next Python versions someone could decide to change cmp(x,0) to another meaning? I bet my countryman (I'm from Holland too ;-) ) will veto that! Or else I'll pay him a visit :D ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why can't I find a function that givesme the sign of aninteger?
On 1/27/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > Orri, > > > Eh you mean to say that in next Python versions someone could decide > > to change cmp(x,0) to another meaning? I bet my countryman (I'm from > > Holland too ;-) ) will veto that! Or else I'll pay him a visit :D > > Its not another meaning, its the current meaning. > Kent is just pointing out that while the default cmp currently > returns -1,0,1 > there is nothing to stop a user defined cmp fom returning any negative or > positive number instead of -1,1. And cmp() calls any user defined cmp > under the hood. > > In theory the standard cmp could be changed in future although its > unlikely.. > So while it is a nice trick it cannot be relied upon since it depends on a > detail of implementation. In practice I suspect you are fairly safe :-) > > Alan G > > Ok. Well I needed it to reflect -, 0 or + anyways so I should be safe. I needed it to find out the direction of a chessmove so pawns could not walk back and with that and the MIN and the MAX function I could do with 1 for+while loops per direction (hor, vert or diag). Oh, I am now on 32 hours of coding and started with 0 knowledge of Python, PIL and/or Pygame and the 1st release should be out soon :-) Just need to fix castling, promotion and en passant and I'm done! I LOVE PYTHON. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] why can't I find a function that gives me the sign of an integer?
On 1/27/06, Wolfram Kraus <[EMAIL PROTECTED]> wrote: > Rinzwind wrote: > > In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > > I searched on the web for a bit but sgn and sign give me way too many > > discussions about Decimals. python.org <http://python.org> with > > numbers/digits doesn't tell about a function. > > > > Maybe Python uses a different name for it so I am not looking for the > > correct wording :( Sucks not knowing syntax from my memory and having to > > look them up alot). > > > > Wim > > > > > > > D'Oh! > > It works with -1/0/1, too: > x and x/abs(x) > > >>> x = -2 > >>> x and x/abs(x) > -1 > >>> x = 2 > >>> x and x/abs(x) > 1 > >>> x = 0 > >>> x and x/abs(x) > 0 > > HTH, > Wolfram No, I needed the -1 0 and 1 :-) That way whatever you move (like Qd2-d6 or Qd6-d2) I could find the places in between the 2. Same goes for Rd1-Rd8 or Rd8-Rd1). I needed it to multiply with -1, 0, 1 according to what move it was :-) Oh and I allready got it working so I'm all :-) :-) :-) about it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Getting Running File's Name
Why would that be any different under Linux? sys.argv[0] Wim On 1/31/06, Hans Dushanthakumar <[EMAIL PROTECTED]> wrote: > Under WinXP, the variable > sys.argv[0] holds the script file name (including the path). Not sure, > but it may work the same under Linux as well. > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Bryan Carbonnell > Sent: Tuesday, 31 January 2006 3:11 p.m. > To: tutor@python.org > Subject: [Tutor] Getting Running File's Name > > Can Python return the name of the current file's name? > > In other works, if I am running a Python file (MyPythonFile.py) is there > a function that will return 'MyPythonFile.py'? > > This will be used in Linux if that matters. > > Thanks > > -- > Bryan Carbonnell - [EMAIL PROTECTED] > Warning: dates on calendar are closer than they appear. > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need to get unique elements out of a 2.5Gb file
I'd use a database if I was you. Install for instance MYSQL or MudBase or something like that and (if need be use Python) to insert the lines into the database. Only storing unique lines would be failry easy. Other sollution (with the usage of Python): If you must use Python I'd suggest making new smaller files. How about making files that are named with the 1st letter of each line you find and split your file up into as many parts and your lines start with unique characters. You end up with lots of smaller files that just need to be merged together (could be done with 'cat' I think?) or you could read all those files and toss them back into 1 big file. Something like this: Read the 2,5G masterfile Read lines 1 by 1 Make a new file named "1st char of line founnd".txt if it doesn't exist and add the new line otherwise scan this file and see if the line is not there yet and if not there add it. when done: merge all files. Can't be too hard to pull off ;) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: list method help
Chris or Leslie Smith: sorry wrong addess :*( This bit l[:]=l[-1:]+l[0:-1] I think is VERY elegant. When I saw this in your post I tought: DUH. I did the same with 1 line more but I am still new to python ;) Regarding the rest of the 'aside'. What is the reasoning behind this: ### >>> l=range(3) >>> a=l # 'a' is pointing at what 'l' is pointing at >>> l[0]=42 # I make a change to the thing that 'l' points to >>> print a [42, 1, 2] >>> print l [42, 1, 2] >>> ### -Why- are these 2 bound together? Is there a specific reasoning behind it? Cuz in Basic (if we had lists) I'd expect this: ### >>> l=range(3) >>> a=l # 'a' is pointing at what 'l' is pointing at >>> l[0]=42 # I make a change to the thing that 'l' points to >>> print a [0, 1, 2] >>> print l [42, 1, 2] >>> ### To get there you'd need 1 more line: What is the reasoning behind this: ### >>> l=range(3) >>> a=l # 'a' is pointing at what 'l' is pointing at >>> l[0]=42 # I make a change to the thing that 'l' points to >>> a=l <--- this one added by ME. >>> print a [42, 1, 2] >>> print l [42, 1, 2] >>> ### Oh and I DO think it's a cool feature btw. But I had me guessing alot too. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list method help
On 2/3/06, Chris or Leslie Smith <[EMAIL PROTECTED]> wrote: > Rinzwind wrote: > | Well Chris or Leslie Smith. > | > | This bit l[:]=l[-1:]+l[0:-1] I think is VERY elegant. When I saw this > | in your post I tought: DUH. > | I did the same with 1 line more but I am still new to python ;) > | > You're seeing the beauty of the language at work :-) I sure do :) I also love dictionaries, tuples, and lists. Thoroughbred Basic doesn't work like that :* > | Regarding the rest of the 'aside'. > | > | What is the reasoning behind this: > | > | ### > l=range(3) > a=l # 'a' is pointing at what 'l' is pointing at > l[0]=42 # I make a change to the thing that 'l' points to > print a > | [42, 1, 2] > print l > | [42, 1, 2] > > | ### > | > | -Why- are these 2 bound together? Is there a specific reasoning > | behind it? > | > | Cuz in Basic > > Others could give you a really good answer. I am a BASIC/FORTRAN writer > myself, and getting used to the *object* orientation of python took a little > while, but after you get the hang of it, it's not bad. In BASIC you think of 10 FOR P1= 1 TO 1; PRINT 'Hello Chris'; NEXT P1 That Basic not VB ;-) > variables *containing* things, so when you say l=2 and a=l you think of two > variables each containing the (what happens to be) the same thing. In > python, however, mutable objects (like lists) are *pointed to* by the > variable name. so the 'l=range(3)' above tells python to create a list and > point the variable name 'l' at it. Then when you say 'a=l' you are telling > it to point 'a' at the same thing as 'l'--one object (the list); two > references to it. Yes, I read something about it concerning ID's assigned to variables. So A = [1,2,3,4] has an ID 209370 And L = A gives L the ID 209370 matching them together. It's cool :-) and would save me alot of A=L stmts in Basic. '-) <..> > | What is the reasoning behind this: > | > | ### > l=range(3) > a=l # 'a' is pointing at what 'l' is pointing at > l[0]=42 # I make a change to the thing that 'l' points to > a=l <--- this one added by ME. > print a > | [42, 1, 2] > print l > | [42, 1, 2] > > | ### > > I know what you are getting at, but from what I wrote above do you see the > difference yet? In basic, saying 'a=l' has created a new variable/value item > and if you want the new change to be reflected in a after making a change to > l you have to 'copy it there' with another a=l statement. In python there is > only one object (the [0, 1, 2]) with two variables pointing to it (a and l). > Those pointer-varaibles are like aliases for the same thing. Oh I understand it :) Was just wondering -why-. I sometimes am like a 10 year old wanting not to know how it works by why it was created to work that way. There must be a reason ;-) <..> > > p.s. I am Chris. My wife and I share the same account, so that's why there > is a "or" in the email name :-) > > Well I can't guess if it's you, your wife or you are both behind your PC beating eachother over the head to decide who can answer my questions :-D ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list method help
On 2/3/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > On 2/3/06, Chris or Leslie Smith <[EMAIL PROTECTED]> wrote:>>Others could give you a really good answer. I am a BASIC/FORTRAN writer >>myself, and getting used to the *object* orientation of python took a little >>while, but after you get the hang of it, it's not bad. In BASIC you think of>>variables *containing* things, so when you say l=2 and a=l you think of two>>variables each containing the (what happens to be) the same thing. In >>python, however, mutable objects (like lists) are *pointed to* by the>>variable name. so the 'l=range(3)' above tells python to create a list and>>point the variable name 'l' at it. Then when you say 'a=l' you are telling >>it to point 'a' at the same thing as 'l'--one object (the list); two>>references to it.You definitely have to stop thinking of variables as containers. Theyare pointers or references to values. Another way to think of this is that variables are names for things. You may call me Kent, someone elsemight call me Mr. Johnson or Dad, but if I get a haircut, Kent, Mr.Johnson and Dad all have shorter hair because all three names refer to the same person.Python works the same way. Assignment binds a name to a value. So if I say lst = [0, 1, 2]I have bound the name 'lst' to a particular list whose value, at themoment, is [0, 1, 2]. If I then assign a = lstthis binds the name 'a' to the same value (the list) that 'lst' is boundto. If I change the bound list, you will see the change whether youaccess the list through the name 'a' or the name 'lst'. KentKent that's a perfectly understandable and easy to grasp analogy. But it stays just an analogy ;-)Thing is. We people consist of more than a 1st name to identify ourself. It is 1st name, last name, country, place of birth, town you now live in, street, postal code, number of the house, date of birth and in case of twins or triplets even the time of birth and maybe a bunch more details. But coding is not IRL and isn't a reflection of it either. Coding is alot easier bacause it does not require that 2 variables need to be linked. I have been coding with the knowledge A is A and A is never B. Not even if they contain the same content but they can have the content copied from 1 to another :-P My question might be summed up to:When would I have need of this? Or why do I want it? Where is the benefit?When I look at this:for x in range(3):I know it is shorthand for something like (not exactly but it serves its purpose as an example): x = 0while x<=3 do: x = x +1And I understand why it is done this way: it makes code shorter AND it is even easier to read: a win-win situation. And the same goes for alot of other things in Python. But this assignment sort of puzzles me to why it's done like this (maybe cuz I am not used to it and can not see beyond my own experience in coding (having a blind spot or something like that)).Oh and tell me to shut up and just accept it if you want to ;-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A question
On 2/5/06, Bian Alex <[EMAIL PROTECTED]> wrote: How can I get a string from a random file. For Example: Del ete On : CopyOwner : BnPersonalized: 5PersonalizedName : My Documents I want to get the string after 'Owner' ( In example is 'Bn') 'import re' ? Pls help.helpYou mean like this?>>> line ='Owner:Bn'>>> line = line.split(":")>>> print line ['Owner', 'Bn']>>> print line[1]BnSo you read the lines from the file till you find "Owner:Bn" and split it at the ':'. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDE - Editors - Python
When you code with Python there's only 1 editor Boa Constructor Even the name owns any other editor :-)http://boa-constructor.sourceforge.net/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Logical Sorting [Off-Topic]
Ubuntu Linux does: [EMAIL PROTECTED]:~$ ls -v Desktop GDM-DarkGno.tar.gz foktopicstart test.py~ Examples Muziek foktopicstart~ [EMAIL PROTECTED]:~$Here's a copy of a complete ls http://www.mediacollege.com/cgi-bin/man/page.cgi?topic=lsOn my system it's also included in both the man (man ls) and the info (info ls) page ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor