Re: [Tutor] Hello!
> I don't know if i'm sending the email to the right address but here it goes!. > Would Python be a suitable language for first time learners like me? I suppose it depends on each one but from my experience I try with C and then Java without finding the feeling for it ... Then I learn python over a year ago and I can tell you that it is one of the best for first timers. I am now learning Java and it is much easier after somehow controlling python. (I suppose ruby has to be the same that python). -- Joaquin This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello!
On 09/09/16 17:21, Eric Gardner wrote: > I don't know if i'm sending the email to the right address but here it > goes!. Would Python be a suitable language for first time learners like me? Yes, this is the right address, welcome. And yes, Python is an excellent language with which to learn programming. If you are comfortable with basic computer use you can try my tutorial(see below) or there is a whole web page on the Python site dedicated to new programmers: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello!
I don't know if i'm sending the email to the right address but here it goes!. Would Python be a suitable language for first time learners like me? -- Eric G ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello everybody
On Mon, Jun 13, 2016 at 11:55 PM, Влад <79099012...@yandex.ru> wrote: >Hi. I've just begin with Python? I'm 34. Is it late or what? If it is - > I >will cut it out. What you think guys? >** > Here myself 48 crossed, just started taking python step by step Welcome to the herd >--** >** **, >, PR- Rich PR >+79099012930 >** > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello everybody
On 13/06/16 20:55, Влад wrote: >Hi. I've just begin with Python? I'm 34. Is it late or what? If it is - I >will cut it out. What you think guys? No you are just a young whippersnapper. I've had students use my tutorial in their 70s (and in their pre-teens too) But is this also your start in programming in general? Or can you already program in any other language? If the latter you will find python easy to pick up. If the former you have some extra work to learn the basic concepts as well as how Python implements those concepts. Finally, it will help if you are experienced in general computer use: navigating folders, manipulating files (especially to edit text files), using a command console, etc. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello everybody
On Mon, Jun 13, 2016 at 3:55 PM, Влад <79099012...@yandex.ru> wrote: >Hi. I've just begin with Python? I'm 34. Is it late or what? If it is - I >will cut it out. What you think guys? >** >--** >** **, >, PR- Rich PR >+79099012930 >** > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor You are an hour and a half too late! Late for what? welcome -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello everybody
Hi. I've just begin with Python? I'm 34. Is it late or what? If it is - I will cut it out. What you think guys? ** --** ** **, , PR- Rich PR +79099012930 ** ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello! Questions
On Fri, Feb 19, 2016 at 3:32 PM, Peter Otten <__pete...@web.de> wrote: > > > Also, after reading http://openopc.sourceforge.net/api.html I wonder if it > wouldn't be better to go with the timestamp provided by the server > > bool1.append(opc.read(".watchdog")) > yes but my next step is to load some of this data up to SQL and the timestamp provided by the opc was difficult to manage into a TIME field. I manage to insert the appended data instead with the timestamp generated with my code. I'll work more on that to see if it is possible to get the original timestamp. I don't require high precision just something around the second is ok. > > With a slight modification of Alan's suggestion you could write to a list > of > dicts instead of a dict of lists like so: > > # outside the loop > WANTED = [".watchdog", ".analog1", ".analog2] > data = [] > > # in the loop: > data.append({r[0]:r[1:] for r in opc.read(WANTED)}) > > > Thanks for the helpful hints. I have a ton of questions yet to come! Marco ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello! Questions
Marco Soldavini wrote: Random remarks about your code: > #While loop - scanning and storing OPC values at scan rate > while (abort == 0): The loop continues to work if you change it to while True: > # ESC pressed? > if msvcrt.kbhit() and ord(msvcrt.getch()) == 27: > abort = 1 > break > > # Server up > if opc.ping(): > > > if opc['.run_batch'] == True and rec_started == False: In idiomatic Python you don't compare boolean values, you test: if opc['.run_batch'] and not rec_started: > # Setting arrays for variables > bool1 = [] > ana1 = [] > ana2 = [] > ana3 = [] > ana4 = [] > rec_started = True > > if opc['.run_batch'] == True and rec_started == True: > # scan time > time2 = time.time() > dtime = time2 - time1 > > if dtime > 2 and comm_alarm == False: > dt = datetime.datetime.now() > bool1.append((opc.read('.watchdog') [0],opc.read('.watchdog')[1],dt)) Invoking opc.read(".watchdog") twice looks wrong, the two values might be out of sync. I suspect that you want result = opc.read(".watchdog") bool1.append((result[0], result[1], dt)) Also, after reading http://openopc.sourceforge.net/api.html I wonder if it wouldn't be better to go with the timestamp provided by the server bool1.append(opc.read(".watchdog")) With a slight modification of Alan's suggestion you could write to a list of dicts instead of a dict of lists like so: # outside the loop WANTED = [".watchdog", ".analog1", ".analog2] data = [] # in the loop: data.append({r[0]:r[1:] for r in opc.read(WANTED)}) > ana1.append((opc.read('.analog2')[0],opc.read('.analog2') [1],dt)) > time1 = time2 > > > else: > # scan time > time2 = time.time() > dtime = time2 - time1 > if dtime > 2: > print "ERROR: OPC Server is down” > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello! Questions
On 19/02/16 07:51, Marco Soldavini wrote: > Sorry, Here my code in plaintext > ... thanks >> Better is to use a dictionary with your "variables" >> data[keyName].append(value) > Ok so I will look more into dictionaries, it is like hash tables? Exactly. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello! Questions
Sorry, Here my code in plaintext #While loop - scanning and storing OPC values at scan rate while (abort == 0): # ESC pressed? if msvcrt.kbhit() and ord(msvcrt.getch()) == 27: abort = 1 break # Server up if opc.ping(): if opc['.run_batch'] == True and rec_started == False: # Setting arrays for variables bool1 = [] ana1 = [] ana2 = [] ana3 = [] ana4 = [] rec_started = True if opc['.run_batch'] == True and rec_started == True: # scan time time2 = time.time() dtime = time2 - time1 if dtime > 2 and comm_alarm == False: dt = datetime.datetime.now() bool1.append((opc.read('.watchdog')[0],opc.read('.watchdog')[1],dt)) ana1.append((opc.read('.analog2')[0],opc.read('.analog2')[1],dt)) time1 = time2 else: # scan time time2 = time.time() dtime = time2 - time1 if dtime > 2: print "ERROR: OPC Server is down” Il giorno 19 febbraio 2016 @ 02:18:05, Alan Gauld (alan.ga...@btinternet.com) ha scritto: > Let's say I can have 30-40 variables (so 30-40 append instructions at every > cycle, with same scan rate). Its not clear what the scan rate actually is. How many scans per second? yes scan per second. For example a new fetch every 2 second, so a new append to array every 5 second > shall run for 2 hours and gather let's say 2000 elements in 40 arrays, > could this be a problem in term of computation? Yes it could, but it depends on what size the data is. You need to do some basic math to calculate it out. 40 * 2000 = 80k items. If they are integers then its 4 bytes per item so 320Kbytes. Not too bad. If they are 100 character strings then its into MB but on a modern PC still not too bad. But if it's intended to run in an embedded controller with only 1M of RAM it might be a big issue. Pc for sure, I think with 8GB RAM. I’ll do some detailed calculations about that. > Second question is I want the arguments in the opc.read command not to be > hard coded but coming from a configuration files. OK. You might want to think about what that file format would look like. I’d like to have an xml file or csv file to parse (another topic I wanna learn) and in this file I have a table defining my variables with a name and another field for description > You see the names of my arrays? bool1, ana1, ana2, etc... Is it possible to > derive number and names of these variables from an external files. It is but its usually a bad idea. Better is to use a dictionary with your "variables" as keys and your arrays as values. So your append looks like data = dict() keyName = readFromFile() value = readFromFile() data[keyName].append(value) Ok so I will look more into dictionaries, it is like hash tables? > Let's say in this configuration file I can say I have to read 10 arrays or > 20 arrays and then my program adjust the while cycle consequently. Yes that's doable. > Maybe an array of array where the second dimension is coming from the > config file. I'd use the dictionary approach rather than arrays of arrays. (Which are probably lists of lists in Python.) Thanks! Marco ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello! Questions
On 18/02/16 21:17, Marco Soldavini wrote: > *# While loop - scanning and storing OPC values at scan rate **while *(abort == 0): > > > *# ESC pressed? **if *msvcrt.kbhit() *and *ord(msvcrt.getch()) == 27: > abort = 1 > > As you can see your code is all messed up. You need to post in plain text format. > Let's say I can have 30-40 variables (so 30-40 append instructions at every > cycle, with same scan rate). Its not clear what the scan rate actually is. How many scans per second? > Is this scalable when variables are getting bigger. The variables stay the same size it's the data that gets bigger. But how scalable it is depends on how much memory you have. And how fast your storage devices are. And what else is running on your system at the time. > shall run for 2 hours and gather let's say 2000 elements in 40 arrays, > could this be a problem in term of computation? Yes it could, but it depends on what size the data is. You need to do some basic math to calculate it out. 40 * 2000 = 80k items. If they are integers then its 4 bytes per item so 320Kbytes. Not too bad. If they are 100 character strings then its into MB but on a modern PC still not too bad. But if it's intended to run in an embedded controller with only 1M of RAM it might be a big issue. > Second question is I want the arguments in the opc.read command not to be > hard coded but coming from a configuration files. OK. You might want to think about what that file format would look like. > You see the names of my arrays? bool1, ana1, ana2, etc... Is it possible to > derive number and names of these variables from an external files. It is but its usually a bad idea. Better is to use a dictionary with your "variables" as keys and your arrays as values. So your append looks like data = dict() keyName = readFromFile() value = readFromFile() data[keyName].append(value) > Let's say in this configuration file I can say I have to read 10 arrays or > 20 arrays and then my program adjust the while cycle consequently. Yes that's doable. > Maybe an array of array where the second dimension is coming from the > config file. I'd use the dictionary approach rather than arrays of arrays. (Which are probably lists of lists in Python.) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello! Questions
On Wed, Feb 17, 2016 at 11:13 AM, Alan Gauldwrote: > > My first question is about data types, data structures in general and how > > to organize an efficient loop for recording data. > > > while (stop condition false) > >read data > >write data into local array or something > >wait sample time > > That's a good start. What is the question? > You say you know how to read data fro openopc, so the > first loop line should be fine. > Storing into a list involves the append method: > > myDataList.append(myData) > > and the wait will probably be openopc specific > but if not you can use the time.sleep() function. > > > hth > -- > Alan G Ok here my main loop for gathering data (stripped off some code to make it easier to read): *# While loop - scanning and storing OPC values at scan rate **while *(abort == 0): *# ESC pressed? **if *msvcrt.kbhit() *and *ord(msvcrt.getch()) == 27: abort = 1 *break * *# Server up **if *opc.ping(): *if *opc[*'.run_batch'*] == True *and *rec_started == False: *# Setting arrays for variables *bool1 = [] ana1 = [] ana2 = [] ana3 = [] ana4 = [] rec_started = True *if *opc[*'.run_batch'*] == True *and *rec_started == True: *# scan time *time2 = time.time() dtime = time2 - time1 *if *dtime > 2 *and *comm_alarm == False: dt = datetime.datetime.now() bool1.append((opc.read(*'.watchdog'*)[0],opc.read( *'.watchdog'*)[1],dt)) ana1.append((opc.read(*'.analog2'*)[0],opc.read(*'.analog2'* )[1],dt)) time1 = time2 *else*: *# scan time *time2 = time.time() dtime = time2 - time1 *if *dtime > 2: *print **"ERROR: OPC Server is down"* As you can see I am using append to store data from opc.read command which returns elements of string array. Let's say I can have 30-40 variables (so 30-40 append instructions at every cycle, with same scan rate). Is this scalable when variables are getting bigger. What if this program shall run for 2 hours and gather let's say 2000 elements in 40 arrays, could this be a problem in term of computation? Second question is I want the arguments in the opc.read command not to be hard coded but coming from a configuration files. You see the names of my arrays? bool1, ana1, ana2, etc... Is it possible to derive number and names of these variables from an external files. Let's say in this configuration file I can say I have to read 10 arrays or 20 arrays and then my program adjust the while cycle consequently. Maybe an array of array where the second dimension is coming from the config file. Is this clear? Version of python is 2.7.9 running on Windows 7. Cheers, Marco ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello! Questions
Hi, I am almost new to python and I am trying to build a not so easy app (but very neat and useful) related to industrial automation. Is this the right place to knock down problems one by one? Basically my app has several interactions but the most important is reading values from an embedded machine (better a PLC) via the OPC protocol. I already tested this with some values of various kind (real, boolean, strings). Basically each tag is read with a fixed sample time from a stream opened in OPC and recorded onto an array in python. Is it better I explain you the main picture? I am not here for spoon feeding but just tips and suggestion and maybe solution to particular problems I might find on the track. Something about OPC is here: https://opcfoundation.org/about/what-is-opc/ The lib I am using is openopc. My first question is about data types, data structures in general and how to organize an efficient loop for recording data. Basically something like while (stop condition false) read data ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello! Questions
I hit the send button too early. anyway Basically something like while (stop condition false) read data write data into local array or something wait sample time Thanks marco ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] hello.
http://pictmania.com/tez.php___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
eryksun wrote: On Tue, Apr 16, 2013 at 7:57 PM, Virgilio Rodriguez Jr virgiliorodrigue...@gmail.com wrote: Can someone please do me the favor and remove me from this god forsaken email list I am sorry I signed up all it has done is taken over my phone and rings all night long with emails I am not interested in any more because it is just too many darn emails. I keep trying to log in and nothing it will not let me unsubscribe and it is BS already. You can get a password reminder here: http://mail.python.org/mailman/options/tutor If you're sure that you have the correct password and still can't unsubscribe, then email the administrator, tutor-ow...@python.org. Alan Gauld is active in this thread, BTW, in case you happen to have read the admin page where it says Tutor list run by wescpy at gmail.com, alan.gauld at btinternet.com. Or switch to digest mode which will email once a day with all the messages in it. Be glad you are not subscribed to the main Python mailing list as it is far more active than the tutor list. ;) ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello, and a newbie question
Hey folks. I'm just starting to pick up Python, and I'd like to avoid some of the mistakes I made in the past. To elaborate on that, my primary programming/scripting experience is PHP, with a little bit of Perl thrown in. Like so many people who write in PHP, I was entirely self-taught, and would be the first to admit that a lot of what I've written is, well... wrong. It works, but it's sloppy and inefficient, because there were standard constructions and solutions I just didn't know about. I'd like to avoid that with Python. So: my first two questions to the list. 1) Python 2.7 or 3.x? I know I'm going to want to do some work with NLTK (which appears to only have an alpha version out for Python 3), but I've just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3, and I'd rather not start learning something that's already obsolete. Any words of advice? 2) Best practices. I have the WROX Press Beginning Python book, which targets Python 2. Clearly that's of only limited value if I'm going to go with Python 3, but it looks like it's at least going to be a good overview. But some of the stuff they do seems to be fairly personalized, rather than trying to follow standards. Should I just start out with the tutorial from docs.python.org? I would assume that that would start putting me in the right habits from the beginning... is that accurate, or is there a better way to go? Thanks in advance, Andy McKenzie ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On 16/04/13 16:58, Andy McKenzie wrote: 1) Python 2.7 or 3.x? I know I'm going to want to do some work with NLTK (which appears to only have an alpha version out for Python 3), but I've just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3, and I'd rather not start learning something that's already obsolete. Any words of advice? Upgrading from P2 to P3 is not too onerous but there will be some changes to make at some po9nt. However P2 is the one to go for if you want to do anything industrial just now because not all the 3rd party libraries (like NLTK) are fully ported to v3 yet, including some pretty significant ones. OTOH If you are only experimenting/learning then going with P3 will avoid any relearning in the future. 2) Best practices. I have the WROX Press Beginning Python book, Sorry, I've never even seen that one so can't comment... http://docs.python.org? I would assume that that would start putting me in the right habits from the beginning... is that accurate, Yes, for existing programmers new to Python the official tutor is nearly always the best place to start. You can fill in the gaps elsewhere later. And the tutor is pretty short and fast paced, you can just about get through it all in an afternoon - certainly in a day. -- Alan G 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] Hello, and a newbie question
On 04/16/2013 11:58 AM, Andy McKenzie wrote: Hey folks. I'm just starting to pick up Python, and I'd like to avoid some of the mistakes I made in the past. To elaborate on that, my primary programming/scripting experience is PHP, with a little bit of Perl thrown in. Like so many people who write in PHP, I was entirely self-taught, and would be the first to admit that a lot of what I've written is, well... wrong. It works, but it's sloppy and inefficient, because there were standard constructions and solutions I just didn't know about. I'd like to avoid that with Python. Welcome to the mailing list. I expect you'll find Python a much cleaner language than the other two, though php has some definite convenience for its particular niche. So: my first two questions to the list. 1) Python 2.7 or 3.x? I know I'm going to want to do some work with NLTK (which appears to only have an alpha version out for Python 3), but I've just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3, and I'd rather not start learning something that's already obsolete. Any words of advice? If you have to use a library that's not available yet for 3.x, then you need to use 2.x on the other hand, if you're learning now, maybe that library will be available by the time you actually need it. For most people, I'd advise against trying to use a tutorial that targets a different version than you're running. If you get frustrated quickly, you can get bogged down by the differences when you're just copying an exact program out of some book. Python 3 in particular has spent some substantial effort cleaning up the warts, the biggest one being Unicode. For beginning programmers using only ASCII, probably the main thing that'll bog you down is that print() is now a function, rather than a statement, so you need parentheses. But once you get used to seeing syntax error, you quickly get the hang of it. And once you do, the function is much nicer. 2) Best practices. I have the WROX Press Beginning Python book, which targets Python 2. Clearly that's of only limited value if I'm going to go with Python 3, but it looks like it's at least going to be a good overview. But some of the stuff they do seems to be fairly personalized, rather than trying to follow standards. Should I just start out with the tutorial from docs.python.org? I would assume that that would start putting me in the right habits from the beginning... is that accurate, or is there a better way to go? Thanks in advance, Andy McKenzie I'd start with the python.org tutorial for the version you're trying to learn. Get serious about trying everything, and don't try to absorb it all in one sitting, even though it can be done. And use a text editor that helps you indent, or even that colorizes your code. And when you just want to try things, use the interpreter directly. It's amazing what you can learn directly from it. You can ask the interpreter lots of questions about an object: help(obj) dir(obj) print( type(obj) ) print( repr(obj) ) And don't forget to post here when you seem to be stuck. Sometimes a well placed comment beats days of struggling. When you do get an exception you don't understand, paste the whole thing, as well as the code you were trying. Best of luck. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On Tue, Apr 16, 2013 at 4:18 PM, Dave Angel da...@davea.name wrote: On 04/16/2013 11:58 AM, Andy McKenzie wrote: Hey folks. I'm just starting to pick up Python, and I'd like to avoid some of the mistakes I made in the past. To elaborate on that, my primary programming/scripting experience is PHP, with a little bit of Perl thrown in. Like so many people who write in PHP, I was entirely self-taught, and would be the first to admit that a lot of what I've written is, well... wrong. It works, but it's sloppy and inefficient, because there were standard constructions and solutions I just didn't know about. I'd like to avoid that with Python. Welcome to the mailing list. I expect you'll find Python a much cleaner language than the other two, though php has some definite convenience for its particular niche. So: my first two questions to the list. 1) Python 2.7 or 3.x? I know I'm going to want to do some work with NLTK (which appears to only have an alpha version out for Python 3), but I've just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3, and I'd rather not start learning something that's already obsolete. Any words of advice? If you have to use a library that's not available yet for 3.x, then you need to use 2.x on the other hand, if you're learning now, maybe that library will be available by the time you actually need it. For most people, I'd advise against trying to use a tutorial that targets a different version than you're running. If you get frustrated quickly, you can get bogged down by the differences when you're just copying an exact program out of some book. Python 3 in particular has spent some substantial effort cleaning up the warts, the biggest one being Unicode. For beginning programmers using only ASCII, probably the main thing that'll bog you down is that print() is now a function, rather than a statement, so you need parentheses. But once you get used to seeing syntax error, you quickly get the hang of it. And once you do, the function is much nicer. 2) Best practices. I have the WROX Press Beginning Python book, which targets Python 2. Clearly that's of only limited value if I'm going to go with Python 3, but it looks like it's at least going to be a good overview. But some of the stuff they do seems to be fairly personalized, rather than trying to follow standards. Should I just start out with the tutorial from docs.python.org? I would assume that that would start putting me in the right habits from the beginning... is that accurate, or is there a better way to go? Thanks in advance, Andy McKenzie I'd start with the python.org tutorial for the version you're trying to learn. Get serious about trying everything, and don't try to absorb it all in one sitting, even though it can be done. And use a text editor that helps you indent, or even that colorizes your code. And when you just want to try things, use the interpreter directly. It's amazing what you can learn directly from it. You can ask the interpreter lots of questions about an object: help(obj) dir(obj) print( type(obj) ) print( repr(obj) ) And don't forget to post here when you seem to be stuck. Sometimes a well placed comment beats days of struggling. When you do get an exception you don't understand, paste the whole thing, as well as the code you were trying. Best of luck. Thanks for the advice, folks. Given that it looks like the biggest changes are unicode handling (which I'm not going to need any time soon) and the way the print function works, I decided to stick with 2.7. I'm an IT guy, though unemployed at the moment, and it occurred to me that I'm familiar with Python, but not the version your entire established codebase is in wasn't a great thing to have on a resume. Since it looks like the new formatting for print -- that is, print(Print this stuff!) -- works fine in 2.7, I'm just getting myself used to doing that from the beginning. I went through the first four or five sections of the tutorial this afternoon, with a few side trips into things that got me interested, and I figure I'll do at least one more section after dinner. I did find it interesting that one of the first things I wanted to know turned out to be an extremely common question: What's the Python equivalent to print_r() from PHP? If any of you are familiar with PHP (I know at least a couple of you seemed to be), you'll know that pprint() (which seems to be the most common answer) isn't actually very close. Its output isn't nearly as readable. For instance: output of running print_r on a very short dictionary from PHP: Array ( [key3] = thing3 [key2] = thing2 [key1] = thing1 ) And running pprint on the same dict in Python: {'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'} I finally decided that a good project would be building a quick function that recreates the print_r
Re: [Tutor] Hello, and a newbie question
On 04/16/2013 05:20 PM, Andy McKenzie wrote: SNIP Thanks for the advice, folks. Given that it looks like the biggest changes are unicode handling (which I'm not going to need any time soon) and the way the print function works, I decided to stick with 2.7. I'm an IT guy, though unemployed at the moment, and it occurred to me that I'm familiar with Python, but not the version your entire established codebase is in wasn't a great thing to have on a resume. Since it looks like the new formatting for print -- that is, print(Print this stuff!) -- works fine in 2.7, I'm just getting myself used to doing that from the beginning. The degenerate print, where you're printing exactly one thing, works the same. But if you have two things to print, putting parens around them in Python 2.x will cause a tuple to be printed, rather than printing the two with a space between. print(3,5) -- version 2.x (3, 5) print(3,5) -- version 3.x 3 5 To get 3.x functionality, you'd want to use from __future__ import print_function and I do not think that works in 2.6 or older versions. It also can be awkward even in 2.7 if you're mixing existing code with new print functions. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On Tue, Apr 16, 2013 at 5:31 PM, Dave Angel da...@davea.name wrote: On 04/16/2013 05:20 PM, Andy McKenzie wrote: SNIP Thanks for the advice, folks. Given that it looks like the biggest changes are unicode handling (which I'm not going to need any time soon) and the way the print function works, I decided to stick with 2.7. I'm an IT guy, though unemployed at the moment, and it occurred to me that I'm familiar with Python, but not the version your entire established codebase is in wasn't a great thing to have on a resume. Since it looks like the new formatting for print -- that is, print(Print this stuff!) -- works fine in 2.7, I'm just getting myself used to doing that from the beginning. The degenerate print, where you're printing exactly one thing, works the same. But if you have two things to print, putting parens around them in Python 2.x will cause a tuple to be printed, rather than printing the two with a space between. print(3,5) -- version 2.x (3, 5) print(3,5) -- version 3.x 3 5 To get 3.x functionality, you'd want to use from __future__ import print_function and I do not think that works in 2.6 or older versions. It also can be awkward even in 2.7 if you're mixing existing code with new print functions. That's good to know, since I hadn't run into it yet. So am I correct in understanding that I can just put the from __future__ import print_function in each new 2.7 script, and get identical functionality to what happens in 3.x? Or do I need to do that system-wide somehow? -Andy ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On 04/16/2013 05:47 PM, Andy McKenzie wrote: On Tue, Apr 16, 2013 at 5:31 PM, Dave Angel da...@davea.name wrote: SNIP To get 3.x functionality, you'd want to use from __future__ import print_function and I do not think that works in 2.6 or older versions. It also can be awkward even in 2.7 if you're mixing existing code with new print functions. That's good to know, since I hadn't run into it yet. So am I correct in understanding that I can just put the from __future__ import print_function in each new 2.7 script, and get identical functionality to what happens in 3.x? Or do I need to do that system-wide somehow? Someone else may know if identical has some exceptions. But as for where to put it, you'd need it for any module (including your own script) which is going to use the newer print() function. And the nice thing is that the from-future directive is ignored in 3.x, so you don't have to remove it when you do progress. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On 16/04/13 22:20, Andy McKenzie wrote: For instance: output of running print_r on a very short dictionary from PHP: Array ( [key3] = thing3 [key2] = thing2 [key1] = thing1 ) And running pprint on the same dict in Python: {'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'} I finally decided that a good project would be building a quick function that recreates the print_r function, and I got that working. New function output, in Python: ( [key3] = thing3 [key2] = thing2 [key1] = thing1 ) You should probably use {} instead of () as the delimiter to indicate that the thing is a dictionary and not a tuple. but otherwise that's a good starter project. -- Alan G 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] Hello, and a newbie question
On Tue, Apr 16, 2013 at 6:17 PM, Dave Angel da...@davea.name wrote: Someone else may know if identical has some exceptions. But as for where to put it, you'd need it for any module (including your own script) which is going to use the newer print() function. I think any differences will result from the I/O system redesign in 3.x. In 2.x sys.stdout is still the old file type, which is basically a wrapper around CRT FILE streams, while in 3.x it's a TextIOWrapper wrapping a BufferedWriter wrapping a FileIO object. Off the top of my head I don't have a clear example where it matters. I vaguely recall having an issue with the default buffer flushing not being the same. I think I was simulating scrolling text by printing a carriage return ('\r') to overwrite a line. IRRC, in the end I opted to directly use sys.stdout.write() and sys.stdout.flush(). Since __future__ imports are compiler directive, you have to include them at the top of every module. print_function works in 2.6+. If you just want the function under a different name, you can grab it from the __builtin__ module: import __builtin__ printf = getattr(__builtin__, 'print') printf('spam') spam ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On Tue, Apr 16, 2013 at 7:39 PM, Alan Gauld alan.ga...@btinternet.comwrote: On 16/04/13 22:20, Andy McKenzie wrote: For instance: output of running print_r on a very short dictionary from PHP: Array ( [key3] = thing3 [key2] = thing2 [key1] = thing1 ) And running pprint on the same dict in Python: {'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'} I finally decided that a good project would be building a quick function that recreates the print_r function, and I got that working. New function output, in Python: ( [key3] = thing3 [key2] = thing2 [key1] = thing1 ) You should probably use {} instead of () as the delimiter to indicate that the thing is a dictionary and not a tuple. but otherwise that's a good starter project. Good idea. I went with () because I was just trying to duplicate the output in PHP. Now that I've got that, I can start thinking about improvements. Varying the punctuation to match the type would probably be a good idea. Thanks, Andy ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On 17/04/13 01:58, Andy McKenzie wrote: 1) Python 2.7 or 3.x? I know I'm going to want to do some work with NLTK (which appears to only have an alpha version out for Python 3), but I've just gone through the hassle of dealing with an upgrade from PHP 4 to 5.3, and I'd rather not start learning something that's already obsolete. Any words of advice? Python 3.3 is awesome and much cleaner and better than 2.7, and 2.7 is pretty damn good! So if you have a choice, pick 3.3. It's the future of Python, 2.7 is the past. But, 2.7 is still good, and if you need NLTK *right now* you might not have a choice. (Unless you like being a guinea pig working with an alpha version.) Also, the *incompatibilities* between 2.7 and 3.3 are fairly small. The biggest difference from a beginner's perspective is that print is no longer a statement, it is a function, so instead of writing this: print Hello world! you have to write this: print(Hello world!) That doesn't seem too onerous, does it? If you can cope with a few differences of that complexity, why not learn both? 2) Best practices. I have the WROX Press Beginning Python book, which targets Python 2. Clearly that's of only limited value if I'm going to go with Python 3, but it looks like it's at least going to be a good overview. But some of the stuff they do seems to be fairly personalized, rather than trying to follow standards. Should I just start out with the tutorial from docs.python.org? I would assume that that would start putting me in the right habits from the beginning... is that accurate, or is there a better way to go? If there's a Python 3 version of Learning Python, from O'Reilly Books (sorry I forget the authors), give it a go. The first edition, at least, is an awesome book although you will want a more recent version since the first edition deals with Python 1.5, which truly is ancient history! I haven't done the official Python tutorial, but from what I've seen of it, it's pretty good. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On Tue, Apr 16, 2013 at 7:57 PM, Virgilio Rodriguez Jr virgiliorodrigue...@gmail.com wrote: Can someone please do me the favor and remove me from this god forsaken email list I am sorry I signed up all it has done is taken over my phone and rings all night long with emails I am not interested in any more because it is just too many darn emails. I keep trying to log in and nothing it will not let me unsubscribe and it is BS already. You can get a password reminder here: http://mail.python.org/mailman/options/tutor If you're sure that you have the correct password and still can't unsubscribe, then email the administrator, tutor-ow...@python.org. Alan Gauld is active in this thread, BTW, in case you happen to have read the admin page where it says Tutor list run by wescpy at gmail.com, alan.gauld at btinternet.com. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On Tue, Apr 16, 2013 at 8:15 PM, eryksun eryk...@gmail.com wrote: Can someone please do me the favor and remove me from this god forsaken email list I am sorry I signed up all it has done is taken over my phone and rings all night long with emails I am not interested in any more because it is just too many darn emails. I keep trying to log in and nothing it will not let me unsubscribe and it is BS already. You can get a password reminder here: http://mail.python.org/mailman/options/tutor If you're sure that you have the correct password and still can't unsubscribe, then email the administrator, tutor-ow...@python.org. Alan Gauld is active in this thread, BTW, in case you happen to have read the admin page where it says Tutor list run by wescpy at gmail.com, alan.gauld at btinternet.com. I just went through the steps. You don't even need your password. Enter your email address in the bottom field of the list info page: http://mail.python.org/mailman/listinfo/tutor Click the button that says Unsubscribe or edit options. Then simply click the Unsubscribe button in the middle of the options page. You'll get a confirmation email with instructions to complete the process. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello, and a newbie question
On 04/17/2013 02:34 AM, eryksun wrote: I just went through the steps. You don't even need your password. Enter your email address in the bottom field of the list info page: http://mail.python.org/mailman/listinfo/tutor Click the button that says Unsubscribe or edit options. Then simply click the Unsubscribe button in the middle of the options page. You'll get a confirmation email with instructions to complete the process. Or send an e-mail to tutor-requ...@python.org with unsubscribe in the subject. ~sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Can someone looked at my problem? stuck
On 3 October 2012 04:39, Palice Fan magicwizards...@gmail.com wrote: Hello i got stuck with the last bit of my programming practice. Can somebody help me? Write a program to read through a mail log, and figure out who had the most messages in the file. The program looks for “From” lines and takes the second parameter on those lines as the person who sent the mail. The program creates a Python dictionary that maps the sender’s address to the total number of messages for that person. After all the data has been read the program looks through the dictionary using a maximum loop (see Section 5.7.2) to find who has the most messages and how many messages the person has. Enter a file name: mbox-short.txt c...@iupui.edu :5 Enter a file name: mbox.txt zq...@umich.edu :195 Instead of printing off a number beside the email, i got another email and i dont know how to fix it. For future reference, please either include the source code in the email as text or as text attachment. A screen capture means I have to retype all your code (and in this case some data) in order to have a look at your problem. Not fun. To fix your problem you have to reverse engineer what's going on in your program. I'll try and walk you through a little thought process in figuring out what's going on to try and help you. The last statement in your program (which is where the error is apparent) prints a fixed email address followed by a value that's assigned earlier on in a loop from the values variable. Consequently you should carefully inspect your code and ask yourself how it's possible that an email address instead of a number is being assigned to the values variable and thereby eventually to the max variable. (By the way, note that max is not recommended as a variable name since max is also a built-in function in Python and so by declaring a variable with the same name you're hiding (known as shadowing) the Python function. You can see there's something special about it by the fact that IDLE colours it purple, which should tip you off.) But anyway, back to your max variable and values variable, we now look back carefully at the loop to see how or where we might be picking up email addresses when we should be getting integer counts... Let's look carefully at the loop declaration: for values in messages: Hmmm, this is looping directly over the dictionary messages. What is returned when you iterate directly over a dict like that? (Hint, it's not the values, but the keys... e.g. the email addresses.) Add some print statements in your loop so you can see what happens when it runs, for example: print 'Starting iterating over messages dict' for values in messages: print 'Value of values this iteration =', values if max is None or values max: print 'Updating max...' max = values print 'Value of max after this iteration =', max If you apply similar changes to your program and run that you'll see why the program doesn't work -- values is being assigned the keys (email addresses) from the dict, not the values. It should also become clear that basically values is also a bad choice for the items being iterated over in the messages dict and is perhaps adding to the confusion, better would be: for email_sender in messages: This would make it clear that the items being iterated over are in fact the email addresses. It's always a good idea to use descriptive specific names in your programs, not least because you yourself also need to read and understand your own code. Anyway, then later in your loop it's then obvious that you can't just do: if max is None or values max: max = values (or if we use my suggested renaming) if max is None or email_sender max: max = email_sender Instead you want to retrieve the actual value (count) from the dict for that specific email sender, e.g. if max is None or messages[email_sender] max: max = messages[email_sender] ... and with that I've now basically explained the essence of your first main problem. However there remains another major flaw. Why are we assigning and outputting 'c...@iupui.edu' as the email address with the maximum number of emails, for any input? Clearly that can't be right - if the input changes and another email address has the highest count then this code will output the wrong result. So in addition to saving the max count, you must also save the max sender in the loop. I think that's enough for now, see if you can fix your program given the above hints and if not post back again. HTH, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hello
On 17/09/2012 20:21, Fation Beqirllari wrote: I have a php code and I want to translate it to python..Can you help me please,or show me how to do it ? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor A better subject would help and no, we don't show you how to do it. You show us that you'd made some sort of attempt at translating the code and run into a problem, then we'll help. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello Python Tutor - help please!
Hi, Cecilia: I came across your posts when catching up with my tutor-request digest emails. I did not see the Udacity site mentioned--if it was, my apologies for the repetition. Udacity.com, a free online education service, offers a number of high-quality courses. They include interactive quizzes using code sandboxes. The courses are 7 weeks long with online office hours and forums. If you do not want to wait for the next start date, you can take the courses online without getting instructor responses to students' posts. Free Interactive Computer Courses (interaction via online quizzes using code sandboxes): http://www.udacity.com/ Intro to Computer Science Python -- Beginner -- Project create functional search engine http://www.udacity.com/view#Course/cs101/CourseRev/apr2012/Unit/671001/Nugget/675002 Programming Languages Python, JavaScript -- Intermediate -- Project: Build a Functional Web Browser http://www.udacity.com/view#Course/cs262/CourseRev/apr2012/Unit/3001/Nugget/5001 Web Application Engineering Python -- Intermediate -- Project: Build a Functional Blog http://www.udacity.com/view#Course/cs253/CourseRev/apr2012/Unit/4001/Nugget/5002 Other courses available. Best regards, Ron Painter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello Python Tutor - help please!
Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
Hello, My highest recommendation for you is to start with a simple hello world program. Study that program, each line. Think about how and most importantly, why it works. Then, extend on it. Make it write to a file instead of a terminal. Then make it read from a file and print to the terminal. Then make it print one letter to each file, then read them back in and reconstruct the sentence. Just take it slow, and one step at a time. So many times people simply go for complex solutions and get lost in the complexity. Sorry for top posting. My phone client doesn't support inline replies. -Mario -- From: Cecilia Chavana-Bryant Sent: 8/22/2012 6:35 AM To: tutor@python.org Subject: [Tutor] Hello Python Tutor - help please! Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
If you don't have any prior programmers skills, i would advice first to learn the basics. You will need a good foundation, before it is possible to create complex functions. Starting with complex functions is only frustrating if you don't understand the basics. From: cecilia.chavana-bry...@ouce.ox.ac.uk To: tutor@python.org Date: Wed, 22 Aug 2012 10:10:46 + Subject: [Tutor] Hello Python Tutor - help please! Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ 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] Hello Python Tutor - help please!
Hello Cecilia, My replies are below, interleaved with your comments, which are prefixed with marks. On 22/08/12 20:10, Cecilia Chavana-Bryant wrote: By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Unfortunately, there will be a certain amount of that, or at least something quite similar to a terminal. Fortunately, using Python in the terminal is usually MUCH easier than C, and in my experience using Python's interactive interpreter is one of the best ways to learn the language. What sort of computer are you using? Windows, Linux, Macintosh, or something different? I think that most of the people here use Linux or Windows, but we can probably help you one way or the other. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. Yes, definitely, but it is still programming. Don't overestimate the difficulty, if it was hard programmers couldn't learn to do it *wink*, but on the other hand it's not trivial either. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. If you are willing to make a good, honest effort on the exercises first, we're happy to help you with them. We do like to see your attempt first, so that we can suggest fixes rather than solve the problem for you. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. I'm entirely with you there. Having direction in your learning is a good thing. But until you understand the basic skills you need, it will be nothing but frustration and pain! I recommend that, if nothing else, you work through some basic tutorials so that you at least have some idea of basic language constructs like: - strings - lists - functions - ints - floats - basic arithmetic - importing modules etc. You could start with the official Python tutorial: http://docs.python.org/tutorial/index.html although I find that it is sometimes a bit wordy. (I should talk...) If you get stuck, don't hesitate to come back and ask questions, that's why we're here. Thus, I was hoping that some of you can remember how you got started I learned from the book Learning Python by Mark Lutz and David Ascher, and then by writing oodles and oodles of really bad code which I have long since thrown away :) [...] So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I feel your pain! That's how I feel every time I try to understand monads in Haskell (don't ask!). How about if you start off with a simple question you would like to solve using Python? Something relevant to your work. You may need to explain some of the concepts to us, since we're not ecologists. (At least, I'm not, I can't speak for others.) We can then try to guide you to a solution and introduce concepts as we go. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
Hola Bill, Many thanks for your reply to my post, you seem to understand the predicament I am in very well. Unfortunately, I am currently working from home and do not have someone close by to help and this is why I came to this space. This is also why I asked for advise about interactive tutorials or video tutorials. I have found that I keep getting lost with the more traditional tutorials where you just read and then do exercises. Following the guide I mentioned on my initial post I got through the first 2 chapters but I found them quite hard going. I don't know if this makes me not a complete beginner but I certainly do not feel like I learned much from reading them. Maybe it is the trying to learn the computer ecosystem of terminal commands at the same time that is making this learning process so tough. With respect to my field data, during my 2 yrs of fieldwork I collected a large amount of data which is currently stored in excel files. My research involves remote sensing (data from Earth-observation satellites) and I work with data from the MODIS NASA satellite which monitors the health of forest canopies using reflectance data. My research is based in the Amazon. I have collected field data to monitor the leaf dynamics of canopy leaves during the dry season. Dry season is the time of year when many tropical trees change their old leaves for new ones. New leaves are more photosynthetically active (absorb more carbon from and release more oxygen into the atmosphere) so the leaf exchange of such a large forest region as the Amazon can have huge effects on regional and global carbon and water cycles and thus on global climate (apologies if I'm giving you loads more information than you need or requested?!). My data involves a large amount of data on leaf demography (we demographically surveyed more than 120,000 leaves), and thousands of morphological and reflectance measurements. I will have to reorganise this data and create a few easily manipulable datasets so I can sort data according to leaf age, canopy position, date, etc. Then I will have to do statistical analyses on the data. I will also have to model some of the data. Many thanks for taking the time to respond to my post so comprehensively and for your good wishes. Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 From: William R. Wing (Bill Wing) [w...@mac.com] Sent: 22 August 2012 15:17 To: Cecilia Chavana-Bryant Cc: William R. Wing (Bill Wing) Subject: Re: [Tutor] Hello Python Tutor - help please! On Aug 22, 2012, at 6:10 AM, Cecilia Chavana-Bryant cecilia.chavana-bry...@ouce.ox.ac.ukmailto:cecilia.chavana-bry...@ouce.ox.ac.uk wrote: Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Could you say a few words about what the field data is, and how you hope to analyze it. That is, are you headed in the direction of plotting species density on maps, or the time evolution of something, or doing statistics? Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I
Re: [Tutor] Hello Python Tutor - help please!
On Wed, Aug 22, 2012 at 11:33 AM, Cecilia Chavana-Bryant cecilia.chavana-bry...@ouce.ox.ac.uk wrote: Hola Bill, Many thanks for your reply to my post, you seem to understand the predicament I am in very well. Unfortunately, I am currently working from home and do not have someone close by to help and this is why I came to this space. This is also why I asked for advise about interactive tutorials or video tutorials. I have found that I keep getting lost with the more traditional tutorials where you just read and then do exercises. Following the guide I mentioned on my initial post I got through the first 2 chapters but I found them quite hard going. I don't know if this makes me not a complete beginner but I certainly do not feel like I learned much from reading them. Maybe it is the trying to learn the computer ecosystem of terminal commands at the same time that is making this learning process so tough. With respect to my field data, during my 2 yrs of fieldwork I collected a large amount of data which is currently stored in excel files. My research involves remote sensing (data from Earth-observation satellites) and I work with data from the MODIS NASA satellite which monitors the health of forest canopies using reflectance data. My research is based in the Amazon. I have collected field data to monitor the leaf dynamics of canopy leaves during the dry season. Dry season is the time of year when many tropical trees change their old leaves for new ones. New leaves are more photosynthetically active (absorb more carbon from and release more oxygen into the atmosphere) so the leaf exchange of such a large forest region as the Amazon can have huge effects on regional and global carbon and water cycles and thus on global climate (apologies if I'm giving you loads more information than you need or requested?!). My data involves a large amount of data on leaf demography (we demographically surveyed more than 120,000 leaves), and thousands of morphological and reflectance measurements. I will have to reorganise this data and create a few easily manipulable datasets so I can sort data according to leaf age, canopy position, date, etc. Then I will have to do statistical analyses on the data. I will also have to model some of the data. Many thanks for taking the time to respond to my post so comprehensively and for your good wishes. Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 From: William R. Wing (Bill Wing) [w...@mac.com] Sent: 22 August 2012 15:17 To: Cecilia Chavana-Bryant Cc: William R. Wing (Bill Wing) Subject: Re: [Tutor] Hello Python Tutor - help please! On Aug 22, 2012, at 6:10 AM, Cecilia Chavana-Bryant cecilia.chavana-bry...@ouce.ox.ac.uk wrote: Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Could you say a few words about what the field data is, and how you hope to analyze it. That is, are you headed in the direction of plotting species density on maps, or the time evolution of something, or doing statistics? Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get
Re: [Tutor] Hello Python Tutor - help please!
On 22/08/12 11:10, Cecilia Chavana-Bryant wrote: I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. At the risk of self promotion you could try the early stages of my tutorial (see .sig). It starts from level zero and explains the concepts of programming before getting started writing code. I personally found that to be fundamental to my learning when I started (and why I included it!). It then goes through the basic programming structures using very simple examples - a multiplication table and address book mainly. (It includes VBScript and Javascript examples too but feel free to ignore them if you find they confuse more than help! The intent is to show the common structures present in all programming languages :-) Whether you progress beyond the first two sections depends on what you want to do next. Those would be enough to start writing programs related to your work and switching to another tutor at that point might be effective. But the concepts topics at the start of my tutor are I think relatively unique, and if diving straight into writing code isn't working maybe a view of the bigger picture will help. -- Alan G 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] Hello Python Tutor - help please!
Hi Cecilia, You've had a lot of good replies already, but I'd like to add the following points if I may: 1) You probably should figure out as much as that's possible up front exactly you're trying to do in terms of data processing first (e.g. some idea of the stats, graphs, summaries, operations etc), and then figure out whether Python is in fact the quickest/best way to get there for you. Python is very capable, it has many data analysis libraries and so on and is used by many scientists (NumPy, SciPy, Pandas comes to mind offhand), but then there are also many other languages and system also appropriate in this sphere. (R comes to mind.) Your goal (from my point of view) is not to become a programmer, but to get your research done. Python may be the way to achieve that, but from where I'm sitting it may also not be. 2) It may be useful to take some suitable courses from some of the very good free online courses now available from various sources such as Coursera. Some examples that seem relevant: Computing for Data Analysis: https://www.coursera.org/course/compdata Mathematics Biostatistics Boot camp: https://www.coursera.org/course/biostats Data Analysis https://www.coursera.org/course/dataanalysis There are also courses covering basic programming, including Python, for example: https://www.coursera.org/course/programming1 HTH, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
I highly recommend the Google Python class that is found on YouTube. The first video is found at http://www.youtube.com/watch?v=tKTZoB2Vjuk The supporting class materials and assignments are found at http://code.google.com/edu/languages/google-python-class/ . This series of videos begins at a pretty basic level, but subsequent videos increase the difficulty level pretty rapidly. Don't despair - the concept of how to properly manipulate strings, lists, tuples, and other objects is rather daunting, but if you're working on your doctoral studies, you already know that complex concepts aren't simply soaked up like water to a sponge ;). Ray On 08/22/2012 03:10 AM, Cecilia Chavana-Bryant wrote: Dear all, I am just returning to my doctoral studies after a 7-month medical leave and desperately trying to catch up for lost time. I am COMPLETELY new to programming, well, I did try learning C for 3 weeks 3 yrs ago (with very little success) but had to stop and then spent 2 years in the Amazon climbing trees (lots more enjoyable than learning to programme!) and collecting loads of field data that I now need to post-process and analyse. By the way, the 3 weeks I spent trying to learn C really ended up being spent trying to get to grips with using a terminal for the first time in my life. Since getting back to work, I was advised to try learning Python instead of C as it is a much easier first language to learn. I have been trying, but again, to not great success. I started following A Primer on Scientific programming with Python but I kept getting lost and stuck, specially on the exercises. I have also been advised that I should not try to learn programming by following guides but by trying to write the programmes I need to analyse my data. Although I can understand the logic behind this last bit of advise (it gives context and direction to the learning process) I have also gotten stuck trying this approach as I do not know how to programme!. Thus, I was hoping that some of you can remember how you got started and point me towards any really good interactive learning guides/materials and/or have a good learning strategy for a complete beginner. I have searched the web and was overwhelmed by choice of tutorials and guides. I have skimmed through a couple of tutorials but then fail to see how all that relates to my own work and I get stuck with what seems like basic important concepts so I don't progress. I then think I should try to make some progress with my own data analysing and go back to trying to learn to write a programme for my specific needs and get stuck again because this requires more advanced skills then the basic programming concepts I have been reading about on the learning guides. So, I am now feeling VERY frustrated and have no idea what on Earth I am doing! Can anyone please offer guidance in my learning process? I don't know how and what I should be spending my time learning first and/or if I should focus my learning towards the skill areas I will require to write my specific programmes, although I have no idea what these are. I would like advise on finding some really good interactive(let you know if your solution to an exercise is correct or not) and or video tutorials that give you feedback on the solutions you write to exercises. Many thanks in advance for all your help, it will be much appreciated! Cecilia Chavana-Bryant DPhil Candidate - Remote sensing and tropical phenology Environmental Change Institute School of Geography and the Environment University of Oxford South Parks Road, Oxford, OX1 3QY Web: http://www.eci.ox.ac.uk/teaching/doctoral/chavanabryantcecilia.php Tel Direct: +44 (0)1865 275861 Fax: +44 (0)1865 275885 ___ 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] Hello Python Tutor - help please!
Steven, (now from my new account without all the long-winded signature) can files be attached to posts in this forum? Cecilia ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello Python Tutor - help please!
On 22/08/12 22:51, Cecilia Chavana-Bryant wrote: Steven, (now from my new account without all the long-winded signature) can files be attached to posts in this forum? Yes they can, but we prefer if you just include them in the body if they are fairly short (100 lines?) or put them on a pastebin with a link. Some mail tools/servers/smartphones don't like mail attachments. -- Alan G 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] Hello Python Tutor - help please!
On 22/08/12 21:51, Cecilia Chavana-Bryant wrote: def main(fname, sheet_name): wb = xlrd.open_workbook(fname) sh = wb.sheet_by_name(sheet_name) data1 = sh.col_values(0) data2 = sh.col_values(1) return data1, data2 fname = Cal_File_P17.xlsx sheet_name = RefPanelData (data1, data2) = main(fname) print data1, data2 ... I do not know where the data is being saved to. That's because it isn't being saved anywhere, it gets thrown away after printing it. If you want to save it you need to augment/replace the print statement with a file write statement(s) You could also write it out using the OS redirection facility. On Unix (ie Your MacOS Terminal) thats done by running the program like: $ python myprog.py myOutputFile.txt Where you substitute your own desired program name and output filename of course! But that will just create a text file that looks like the output displayed on the Terminal, which is not, I think, what you are after. You probably want to do some extra work to save as a csv file. However, before you do that you could look at using the spreadsheet's SaveAs feature to export as a CSV directly, but it depends on how many spreadsheets you need to convert! HTH -- Alan G 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] hello~
as you can see i only use some of the command. it doesnt produce an error message tho.. just repeats return Error(b%s/b I couldn't find %s anywhere, user.name.title(), name.title()) Your problem might be is indenting of the else. It is indenting to be a for...else loop. Which means that if nothing breaks out of the loop it will always do what is in the else (which in this case returns Error[...]) after the loop has finished running through the rooms. for room in mgr.rooms: if data[1] == join: mgr.sendObject(target, Html(b%s/b, bfont color='#3399CC'%s/font/b wants to tell you bi%s/i/b, name.title, user.name.title$ else: return Error(b%s/b I couldn't find %s anywhere, user.name.title(), name.title()) Why are you looping through the rooms and checking if data[1] == join? You do not even use the room object in the loop, and target is not defined in the local scope, although I suppose you meant to use room instead. This loop just smells to me. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hello~
i resent it but if that doesnt work. cause i sent it to myself also looks fine on my gmail.. but heres a link to pastebin http://pastebin.com/Jp7VJKGB maybe thatll help? On Mon, May 14, 2012 at 1:43 AM, Russel Winder rus...@winder.org.uk wrote: On Mon, 2012-05-14 at 00:19 +0100, Mark Lawrence wrote: [...] Sorry but it's unreadable to me. Have you sent this in HTML when you should have sent in plain text? I think it is just line wrapping, email still is supposed to have no lines greater that 78 characters (RFC 2822) and some email clients enforce this on sending by amending what the author thought they sent. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- ~~Austin ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] hello~
hey. Austin here for some reason this command. all it does it produces the error message at the bottom.. itll say my name and the persons name im trying to send the message to but thats it. heres the command. mgr.addCommand(tell, 1, send a person a message to the rooms he is in, tell, unlisted = True) def tell(mgr, croom, user, msg, args): name = args.lower().split( )[0] if not name.isalnum(): return Html(Non-alphanumeric name, seriously?) data = shared_db.get(seen: + name) if data == None: return Html(I have no records about this user.) data = json.loads(data) for room in mgr.rooms: if data[1] == join: mgr.sendObject(target, Html(b%s/b, bfont color='#3399CC'%s/font/b wants to tell you bi%s/i/b, name.title, user.name.title$ else: return Error(b%s/b I couldn't find %s anywhere, user.name.title(), name.title()) i built it off these 2 commands def broadcast(mgr, croom, user, msg, args): for room in mgr.rooms: mgr.sendObject(room, Html(Broadcast by b%s/b:%s, user.name, args)) def seen(mgr, room, user, msg, args): name = args.lower().split( )[0] if not name.isalnum(): return Html(Non-alphanumeric name, seriously?) data = shared_db.get(seen: + name) if data == None: return Html(I have no records about this user.) data = json.loads(data) ifdata[1] == join: return Html(Last seen b%s/b join b%s/b, b%s/b ago., name, data[0], tdelta(data[2])) elif data[1] == leave: return Html(Last seen b%s/b leave b%s/b, b%s/b ago., name, data[0], tdelta(data[2])) elif data[1] == message: return Html(Last seen b%s/b message in b%s/b, b%s/b ago: i\%s\/i, name, data[0], tdelta(data[2]), data[3]) return Html(I have no records about this user.) as you can see i only use some of the command. it doesnt produce an error message tho.. just repeats return Error(b%s/b I couldn't find %s anywhere, user.name.title(), name.title()) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hello~
On 14/05/2012 00:04, Keitaro Kaoru wrote: hey. Austin here for some reason this command. all it does it produces the error message at the bottom.. itll say my name and the persons name im trying to send the message to but thats it. heres the command. mgr.addCommand(tell, 1, send a person a message to the rooms he is in, tell, unlisted = True) def tell(mgr, croom, user, msg, args): name = args.lower().split( )[0] if not name.isalnum(): return Html(Non-alphanumeric name, seriously?) data = shared_db.get(seen: + name) if data == None: return Html(I have no records about this user.) data = json.loads(data) for room in mgr.rooms: if data[1] == join: mgr.sendObject(target, Html(b%s/b,bfont color='#3399CC'%s/font/b wants to tell youbi%s/i/b, name.title, user.name.title$ else: return Error(b%s/b I couldn't find %s anywhere, user.name.title(), name.title()) i built it off these 2 commands def broadcast(mgr, croom, user, msg, args): for room in mgr.rooms: mgr.sendObject(room, Html(Broadcast byb%s/b:%s, user.name, args)) def seen(mgr, room, user, msg, args): name = args.lower().split( )[0] if not name.isalnum(): return Html(Non-alphanumeric name, seriously?) data = shared_db.get(seen: + name) if data == None: return Html(I have no records about this user.) data = json.loads(data) ifdata[1] == join: return Html(Last seenb%s/b joinb%s/b,b%s/b ago., name, data[0], tdelta(data[2])) elif data[1] == leave: return Html(Last seenb%s/b leaveb%s/b,b%s/b ago., name, data[0], tdelta(data[2])) elif data[1] == message: return Html(Last seenb%s/b message inb%s/b,b%s/b ago: i\%s\/i, name, data[0], tdelta(data[2]), data[3]) return Html(I have no records about this user.) as you can see i only use some of the command. it doesnt produce an error message tho.. just repeats return Error(b%s/b I couldn't find %s anywhere, user.name.title(), name.title()) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor Sorry but it's unreadable to me. Have you sent this in HTML when you should have sent in plain text? -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hello~
On Mon, 2012-05-14 at 00:19 +0100, Mark Lawrence wrote: [...] Sorry but it's unreadable to me. Have you sent this in HTML when you should have sent in plain text? I think it is just line wrapping, email still is supposed to have no lines greater that 78 characters (RFC 2822) and some email clients enforce this on sending by amending what the author thought they sent. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello again. Still the same problem, different question.
On 12 November 2011 07:27, 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 Please have a useful subject line next time, the current subject doesn't tell us anything about your problem. Someone there told me they would've given up by now but I am not giving up on this one or anything else. Just to give you a heads up, you will be getting questions about this until this program works. You can't force me to answer questions! Additionally; I, for one, will put you on ignore if you spam this list with questions that are about the same subject and are unsolvable because the standard version doesn't work. So just to give you a heads up: don't overextend your welcome. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello again. Still the same problem, different question.
I realize that one of you told me that there is no livewires for python v3.1.1 but the book that I am reading teaches v3.1.1 and the code that is presented in the book has a line that imports a module from the livewires package. Now since the book covers v3.1.1, I would have to conclude that the code containing the line from livewires import games should work in version 3.1.1. They gave me a website to go and download a version of livewires that would work (www.courseptr.com/downloads) and I went there but I could not find that download anywhere. I think the website might have changed since the book was written. If anybody knows where I can get the version of livewires I need I would be truly greatful. My book is entitled Python Programming for the Absolute Beginner Third Edition. Anyway, here is the code that my book insists should work. # New Graphics Window # Demonstrates creating a graphics window from livewires import games games.init(screen_width = 640, screen_height = 480, fps = 50) games.screen.mainloop() and here is the error message I keep getting Traceback (most recent call last): File C:\Python27\new_graphics_window.py, line 6, in module games.init(screen_width = 640, screen_height = 480, fps = 50) AttributeError: 'module' object has no attribute 'init' Someone there told me they would've given up by now but I am not giving up on this one or anything else. Just to give you a heads up, you will be getting questions about this until this program works. Thanks for your help. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello again. Still the same problem, different question.
Can you kindly mail the author? That might be a better way to have this resolved. Its interesting you are sticking with python v3. Cheers. Sent from my BlackBerry wireless device from MTN -Original Message- From: Nathaniel Trujillo hothottr...@gmail.com Sender: tutor-bounces+delegbede=dudupay@python.org Date: Fri, 11 Nov 2011 21:16:30 To: Tutor@python.org Subject: [Tutor] Hello again. Still the same problem, different question. ___ 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] Hello again. Still the same problem, different question.
Nathaniel Trujillo wrote: I realize that one of you told me that there is no livewires for python v3.1.1 but the book that I am reading teaches v3.1.1 and the code that is presented in the book has a line that imports a module from the livewires package. Now since the book covers v3.1.1, I would have to conclude that the code containing the line from livewires import games should work in version 3.1.1. They gave me a website to go and download a version of livewires that would work (www.courseptr.com/downloads) and I went there but I could not find that download anywhere. I think the website might have changed since the book was written. If anybody knows where I can get the version of livewires I need I would be truly greatful. My book is entitled Python Programming for the Absolute Beginner Third Edition. Anyway, here is the code that my book insists should work. According to one of the reviews on Amazon, that's because the author of the book has written his own customized version of Livewires which you have to use. http://www.amazon.ca/Python-Programming-Absolute-Beginner-Second/dp/1598631128 The book quite clearly says so too: TRAP Although you're welcome to visit the web site of the LiveWires organization at http://www.livewires.org.uk , be aware that the livewires package used in this book is a modified version of the package that LiveWires created. Someone there told me they would've given up by now but I am not giving up on this one or anything else. Just to give you a heads up, you will be getting questions about this until this program works. Thanks for your help. While I admire your persistence, we are all volunteers and may not appreciate being asked the same questions over and over and over again to no value. I'm just saying that at some point, you may have to expect that we'll stop answering questions if we think we're just wasting our time. If the author's custom version is not available, and the standard version doesn't work, then we're probably wasting our time. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello again. Still the same problem, different question.
On 2011-11-12 05:16, Nathaniel Trujillo wrote: They gave me a website to go and download a version of livewires that would work (www.courseptr.com/downloads) and I went there but I could not find that download anywhere. http://www.delmarlearning.com/companions/content/1435455002/downloads/index.asp?isbn=1435455002 If you click on Book related software you'll get a zip-file which includes livewires. Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On Saturday 16 July 2011 03:15:12 Richard D. Moores wrote: But that makes me wonder if there isn't a simpler way to do it with Python -- to delete the contents of a file without deleting the file? Up to now, knowing no better ;-), I have opened the file in, or copied and pasted the contents of a file into, a word processor and turned on the non-printing characters. It is then easy to see extraneous spaces, empty lines etc. I then go back to the editor and do the revealed editing. Rough, ready and cobbled - but easy, and it works. ;-) If you use Windows and have no idea what I am talking about, I apologise. It is so long since I used Windows that I have forgotten much of what it can and cannot do; and I don't know whether it can do this. Lisi ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On Sun, Jul 10, 2011 at 05:05, Peter Otten __pete...@web.de wrote: help(print) shows print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. I didn't know that printing to a file with print() was possible, so I tried print(Hello, world!, file=C:\test\test.txt) Traceback (most recent call last): File string, line 1, in fragment builtins.AttributeError: 'str' object has no attribute 'write' And the docs at http://docs.python.org/py3k/library/functions.html#print tell me The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. What do I do to test.txt to make it an object with a write(string) method? Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
Richard D. Moores, 15.07.2011 23:21: On Sun, Jul 10, 2011 at 05:05, Peter Otten wrote: help(print) shows print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. I didn't know that printing to a file with print() was possible, so I tried print(Hello, world!, file=C:\test\test.txt) Traceback (most recent call last): File string, line 1, infragment builtins.AttributeError: 'str' object has no attribute 'write' And the docs at http://docs.python.org/py3k/library/functions.html#print tell me The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. What do I do to test.txt to make it an object with a write(string) method? Oh, there are countless ways to do that, e.g. class Writable(object): def __init__(self, something): print(Found a %s % something)) def write(self, s): print(s) print(Hello, world!, file=Writable(C:\\test\\test.txt)) However, I'm fairly sure what you want is this: with open(C:\\test\\test.txt, w) as file_object: print(Hello, world!, file=file_object) Look up open() (open a file) and the with statement (used here basically as a safe way to make sure the file is closed after writing). Also note that \t refers to a TAB character in Python, you used this twice in your file path string. Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On Fri, Jul 15, 2011 at 14:47, Stefan Behnel stefan...@behnel.de wrote: Richard D. Moores, 15.07.2011 23:21: What do I do to test.txt to make it an object with a write(string) method? Oh, there are countless ways to do that, e.g. class Writable(object): def __init__(self, something): print(Found a %s % something)) def write(self, s): print(s) print(Hello, world!, file=Writable(C:\\test\\test.txt)) However, I'm fairly sure what you want is this: with open(C:\\test\\test.txt, w) as file_object: print(Hello, world!, file=file_object) Yes, went with with open(C:\\test\\test.txt, a+) as file_object: print(Hello, world!, file=file_object) Look up open() (open a file) and the with statement (used here basically as a safe way to make sure the file is closed after writing). Also note that \t refers to a TAB character in Python, you used this twice in your file path string. Oops. I'd forgotten about that. Thanks very much, Stefan and Donald. Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On Friday 2011 July 15 15:58, Richard D. Moores wrote: On Fri, Jul 15, 2011 at 14:47, Stefan Behnel stefan...@behnel.de wrote: Richard D. Moores, 15.07.2011 23:21: What do I do to test.txt to make it an object with a write(string) method? Oh, there are countless ways to do that, e.g. class Writable(object): def __init__(self, something): print(Found a %s % something)) def write(self, s): print(s) print(Hello, world!, file=Writable(C:\\test\\test.txt)) However, I'm fairly sure what you want is this: with open(C:\\test\\test.txt, w) as file_object: print(Hello, world!, file=file_object) Yes, went with with open(C:\\test\\test.txt, a+) as file_object: print(Hello, world!, file=file_object) Look up open() (open a file) and the with statement (used here basically as a safe way to make sure the file is closed after writing). Also note that \t refers to a TAB character in Python, you used this twice in your file path string. I believe on Windows, you can almost always use a forward slash in a path: C:/somewhere/somewhereelse/ -- I have seen the future and I am not in it. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On Fri, Jul 15, 2011 at 16:21, xDog Walker thud...@gmail.com wrote: I believe on Windows, you can almost always use a forward slash in a path: C:/somewhere/somewhereelse/ with open(C:/test/test.txt, a) as file_object: print(Hello, world!, file=file_object) Yes, that works for me with Windows Vista. However, if test.txt is empty, it puts in a blank line as line 1; line 2 is Hello, world!. Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On 07/15/2011 07:39 PM, Richard D. Moores wrote: On Fri, Jul 15, 2011 at 16:21, xDog Walkerthud...@gmail.com wrote: I believe on Windows, you can almost always use a forward slash in a path: C:/somewhere/somewhereelse/ with open(C:/test/test.txt, a) as file_object: print(Hello, world!, file=file_object) Yes, that works for me with Windows Vista. However, if test.txt is empty, it puts in a blank line as line 1; line 2 is Hello, world!. Dick _ I expect that your extra newline was already in the empty file. It cannot have anything to do with using the forward slash for the filename. DaveA -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On Fri, Jul 15, 2011 at 17:16, Dave Angel d...@davea.name wrote: On 07/15/2011 07:39 PM, Richard D. Moores wrote: with open(C:/test/test.txt, a) as file_object: print(Hello, world!, file=file_object) Yes, that works for me with Windows Vista. However, if test.txt is empty, it puts in a blank line as line 1; line 2 is Hello, world!. Dick _ I expect that your extra newline was already in the empty file. It cannot have anything to do with using the forward slash for the filename. I see that you are correct. It seems that selecting all the text in a text file (in Notepad), then hitting the delete key doesn't guarantee that the file will be left truly blank. The way that consistently works for me is to place the cursor in the upper left corner of the file and hold down the delete key. Running with open(C:/test/test.txt, w) as file_object: print(file=file_object) Also works. But that makes me wonder if there isn't a simpler way to do it with Python -- to delete the contents of a file without deleting the file? Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
Richard D. Moores wrote: But that makes me wonder if there isn't a simpler way to do it with Python -- to delete the contents of a file without deleting the file? Opening a file for writing will flush the contents. open(filename, 'w') will do it, taking advantage of Python's garbage collector to (eventually) close the file. The more careful way is hardly any harder: open(filename, 'w').close() and this ensures that the file isn't left open any longer than necessary. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On Fri, Jul 15, 2011 at 21:38, Steven D'Aprano st...@pearwood.info wrote: Richard D. Moores wrote: But that makes me wonder if there isn't a simpler way to do it with Python -- to delete the contents of a file without deleting the file? Opening a file for writing will flush the contents. open(filename, 'w') will do it, taking advantage of Python's garbage collector to (eventually) close the file. The more careful way is hardly any harder: open(filename, 'w').close() and this ensures that the file isn't left open any longer than necessary. open(C:/test/test.txt, 'w').close() Good to know. Thanks, Steven. Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
On 7/10/2011 4:12 AM Robert H said... Dear all, I have Python 3.2 installed on Windows 7. I am a complete beginner playing around with the basic functions. My problem is the following script: name=world print(Hello, name,!) print(Hello, name+!) Alan mentioned using concatenation as well and .join() is generally preferred, particularly when many strings are involved. Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello World in Python without space
Dear all, I have Python 3.2 installed on Windows 7. I am a complete beginner playing around with the basic functions. My problem is the following script: name=world print(Hello, name,!) The result is: Hello world ! However, I don't want the space before the exclamation mark. I want this: Hello world! I tried to solve the problem with e.g.: print(Hello,name.strip(),!) but the result is the same. Can anyone out there help me? Thank you. Regards, Robert ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
Sending args to the print command always puts spaces between them. Try: print(Hello {name}!.format(name=name)) 2011/7/10 Robert H hrober...@hotmail.com Dear all, I have Python 3.2 installed on Windows 7. I am a complete beginner playing around with the basic functions. My problem is the following script: name=world print(Hello, name,!) The result is: Hello world ! However, I don't want the space before the exclamation mark. I want this: Hello world! I tried to solve the problem with e.g.: print(Hello,name.strip(),!) but the result is the same. Can anyone out there help me? Thank you. Regards, Robert ___ 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] Hello World in Python without space
Robert H wrote: I have Python 3.2 installed on Windows 7. I am a complete beginner playing around with the basic functions. My problem is the following script: name=world print(Hello, name,!) The result is: Hello world ! However, I don't want the space before the exclamation mark. I want this: Hello world! I tried to solve the problem with e.g.: print(Hello,name.strip(),!) but the result is the same. print() by default inserts a space between its arguments. You can avoid that by specifying a separator explicitly with the sep keyword. Let me show it in the interactive interpreter which is generally a good place to experiment with small snippets of code: name = Robert print(Hello , name, !, sep=) # Note the explicit after Hello Hello Robert! Another goodie is that you can easily get useful information about modules, classes, keywords, and functions, e. g. help(print) shows print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. Use help() without argument to learn more about the interactive help. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello World in Python without space
Robert H hrober...@hotmail.com wrote name=world print(Hello, name,!) Hello world ! However, I don't want the space before the exclamation mark. I want this: Hello world! Can anyone out there help me? Thank you. I see you've already had two answers, a third is to construct the string before printing it. There are various ways to do that: The simplest: output = Hello + name + ! An alternative which is more efficient for larger numbers of substruings is: output = .join([Hello ,name,!]) # thats an empty string to start The thirs is to use a formatstring, but thats what Izz did in his print call. Whichever method you use you then use print(output) Lots of options. As Peter said, use the prompt to experiment to find which works best for you. -- 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] Hello
This is my first message to this mailing list. I want to create a project with glade and pygtk on fedora. Can you suggest a good IDE? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello
The choice of IDE is quite objective. Many of the people use vim/emacs exclusively for all the work. Eclipse with PyDev plugin too is a good choice. On Thu, Jan 21, 2010 at 11:03 PM, Samuel de Champlain samueldechampl...@gmail.com wrote: This is my first message to this mailing list. I want to create a project with glade and pygtk on fedora. Can you suggest a good IDE? ___ 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] Hello
Check out wingware IDE and Geany. On Thu, Jan 21, 2010 at 12:33 PM, Samuel de Champlain samueldechampl...@gmail.com wrote: This is my first message to this mailing list. I want to create a project with glade and pygtk on fedora. Can you suggest a good IDE? ___ 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] Hello
On Thu, Jan 21, 2010 at 11:03 PM, Samuel de Champlain samueldechampl...@gmail.com wrote: This is my first message to this mailing list. I want to create a project with glade and pygtk on fedora. Can you suggest a good IDE? netbeans have worked quite well for me but its heavy weight if you are looking for something light check out komodo. ___ 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 -- Vishwajeet Singh +91-9657702154 | dextrou...@gmail.com | http://singhvishwajeet.com Twitter: http://twitter.com/vishwajeets | LinkedIn: http://www.linkedin.com/in/singhvishwajeet ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] 'Hello world'
Hi there, I must say I'm quite embarrassed about my issue. Ok, I'm a 101% newbie in programming and all but I honestly didn't expect I would have problems in my very first step which was just to print 'hello world'. Despite some idiot little thing I might be overlooking I wonder if Python 3.1.1 was properly installed in my machine. I got a AMD Turion X2 64 processor and Win7 Pro-64 so I suppose the Python 3.1.1 AMD64 version I got was the best pick right? here it comes: Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit (AMD64)] on win32 Type copyright, credits or license() for more information. print 'hello world!' SyntaxError: invalid syntax (pyshell#0, line 1) print hello world! SyntaxError: invalid syntax (pyshell#1, line 1) Thanks a million, Eldon. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'Hello world'
On Fri, Jan 1, 2010 at 11:17 AM, Eldon L Mello Jr eldo...@hotmail.com wrote: Hi there, I must say I'm quite embarrassed about my issue. Ok, I'm a 101% newbie in programming and all but I honestly didn't expect I would have problems in my very first step which was just to print 'hello world'. Despite some idiot little thing I might be overlooking I wonder if Python 3.1.1 was properly installed in my machine. I got a AMD Turion X2 64 processor and Win7 Pro-64 so I suppose the Python 3.1.1 AMD64 version I got was the best pick right? here it comes: Python 3.1.1 (r311:74483, Aug 17 2009, 16:45:59) [MSC v.1500 64 bit (AMD64)] on win32 Type copyright, credits or license() for more information. print 'hello world!' SyntaxError: invalid syntax (pyshell#0, line 1) print hello world! SyntaxError: invalid syntax (pyshell#1, line 1) Thanks a million, This is something that has changed between Python 2 and Python 3. In Python 2 what you tried is perfectly valid, but in Python 3 print has become a function, so you have to write: print(hello world!) or print('hello world!') Happy New Year! -- André Engels, andreeng...@gmail.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'Hello world'
Eldon L Mello Jr eldo...@hotmail.com wrote programming and all but I honestly didn't expect I would have problems in my very first step which was just to print 'hello world'. print hello world! SyntaxError: invalid syntax (pyshell#1, line 1) Looks like you are using a v2 tutorial, you need to find a v3 one. There are several around, including my own - although it is not fully complete all the basic topics are there now. If you have experience in any other language the official one is probably the best. v3 of Python is a major rewrite and although largely backwardws compatible there are a number of new features that are not. One of the most important is print, but there are several others that will trip you up if you use a v2 tutorial. -- 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] Hello again. and another question.
Hello Trask, I have been working on the first program. I got the files to read and print out the grades and averages, but when I write these files to the other txt file, all that I get is: 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 I know it is something simple. I am just not seeing it. Here is my code: Grades = [ ] filename = raw_input(Enter the filename with 10 grades to be averaged: ) my_file_object = open (filename, r) for a in range (10): temp_string = my_file_object.readline() Grades = Grades + [ float (temp_string)] my_file_object.close() for a in range (len(Grades)): print Grade, str (a + 1) + :, Grades [a] total = 0 for a in range (len(Grades)): total = total + Grades[a] average = total/float (len(Grades)) print The average grade was: , round(average,2) print print Okay, we are assuming that you have created a file named 'grade_file_2.txt' that is empty, yes? print fname= raw_input(Please enter 'grade_file_2.txt' to write to new file: ) grades_file_2 = open(grade_file_2.txt, w) for count in range (len(Grades)): grades_file_2.write(str(%.2f% (len(Grades))) + \n) grades_file_2.close() print print Nice Job. your file is done. /// I am including the files. Let me know if you see anything goofy. Tom Mundahl tm_week11_problem1.py Description: Binary data 10.00 10.00 10.00 10.00 10.00 10.00 10.00 10.00 10.00 10.00 90.50 88.25 98.95 94.90 95.44 96.84 97.99 98.25 99.55 96.88___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello again. and another question.
On Thu, Oct 02, 2008 at 09:41:37PM +, [EMAIL PROTECTED] wrote: for count in range (len(Grades)): grades_file_2.write(str(%.2f% (len(Grades))) + \n) Look at what you're actually writing for each count. See anything amiss there? -- Steve Willoughby| Using billion-dollar satellites [EMAIL PROTECTED] | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello again. and another question.
You're doing a good job getting started with programming here, keep getting the fundamentals and then learn to refine those concepts over time. But for future reference, here are some finer points for you to keep in mind to improve your style and get a more Pythonic approach: On Thu, Oct 02, 2008 at 09:41:37PM +, [EMAIL PROTECTED] wrote: Grades = [ ] Usually we capitalize class and module names, but not variables and functions/methods. for a in range (10): temp_string = my_file_object.readline() Grades = Grades + [ float (temp_string)] Might be more clear here to say Grades.append(float(temp_string)) instead of constructing a new list just to use + You might also want to just read each line in the file right in the for loop, which allows you to take ANY number of lines, not just 10, and makes the code more concise at the same time: for grade in my_file_object: Grades.append(float(grade)) for a in range (len(Grades)): print Grade, str (a + 1) + :, Grades [a] If all you're going to do is to deal with each element of a list in turn, instead of using an index over the range of the number of elements, just directly iterate over the list: for a in Grades: print Grade:, a And one GREAT habit to get into is to always be checking if Python's built in functions and standard library already offer something you're doing manually: total = 0 for a in range (len(Grades)): total = total + Grades[a] average = total/float (len(Grades)) average = sum(Grades) / len(Grades) fname= raw_input(Please enter 'grade_file_2.txt' to write to new file: ) grades_file_2 = open(grade_file_2.txt, w) I'm not sure why you're asking them to type in a file name which you're ignoring and opening grade_file_2.txt anyway? for count in range (len(Grades)): grades_file_2.write(str(%.2f% (len(Grades))) + \n) grades_file_2.close() No need to explicitly call str() here, and I suspect print would be clearer anyway. And again, note the direct iteration over Grades: for grade in Grades: print grades_file_2, %.2f % grade grades_file_2.close() -- Steve Willoughby| Using billion-dollar satellites [EMAIL PROTECTED] | to hunt for Tupperware. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello again. and another question.
[EMAIL PROTECTED] wrote I got the files to read and print out the grades and averages, but when I write these files to the other txt file, all that I get is: 10.0 10.0... I know it is something simple. I am just not seeing it. When the output doesn't vary like this you know you must be writing the wrong value or the same value multiple times. I'll add several comments on the code but the solution is in there too... Grades = [ ] filename = raw_input(Enter the filename with 10 grades to be averaged: ) my_file_object = open (filename, r) for a in range (10): temp_string = my_file_object.readline() Grades = Grades + [ float (temp_string)] my_file_object.close() for a in range (len(Grades)): print Grade, str (a + 1) + :, Grades [a] ## # It would be better to just iterate over Grades: for index, grade in enumerate(Grades): print Grade, index,:,grade total = 0 for a in range (len(Grades)): total = total + Grades[a] ## # same here: for grade in Grades: total += grade average = total/float (len(Grades)) ## # you don't need the float conversion here because you converted them all to floats at the beginning. print The average grade was: , round(average,2) print print Okay, we are assuming that you have created a file named 'grade_file_2.txt' that is empty, yes? print fname= raw_input(Please enter 'grade_file_2.txt' to write to new file: ) grades_file_2 = open(grade_file_2.txt, w) for count in range (len(Grades)): grades_file_2.write(str(%.2f% (len(Grades))) + \n) # # Notice you are writing len(Grades) which is always 10 - your error! But... # # and again the for loop, and simplify the output string: for grade in Grades: grades_file_2.write(%.2f\n % grade) grades_file_2.close() Python for loops are much more powerful when used as foreach loops rather than always using indexing. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello and some questions.
Hello all. I recently starting taking Python in my state college. I joined the Python.org users group and I posted a couple of codes examples that I was having problems with, and I am wondering if there is anyone in this community that can help me. I did get some great advice on my previous posts however my code is still not working. I have two problems that I have to write code for. The first problem is a program that will take a list of ten grades from a user and then calculate the average of the ten numbers entered. The user can only use the numbers 1-10. Example. The total average of the grades you entered in was 5 which would be the average using number 1-10 in a sequence, but it needs to calculate an average no matter if the user puts in 3 5's and 7 10's. The average must be calculated. I did get some help in the python forums with this and I have come up the following, but I am getting a syntax error on the line that calls out total as a variable. Here is the code: value = [ ] for i in range(10): range += 1 print (int(float(raw_input(Please enter a grade, use numbers 1 - 10: ))) # getting a syntax error on this line total = sum(value) average = total/10.0 print The average sum of all of the grades that you entered is , (%.2f % average) raw_input(\nPlease hit enter to quit.) ///The code does not work. The next problem is supposed to use the while loop. A user is supposed to enter some grade values. The user will continue to be prompted to enter grade values until the user has entered in as a grade value. Then the program is supposed to calculate the average of all of the grades entered including the . Here is my code, This code is not working either: target = value = [ ] while i in value or not == target: i += 1 print grade (int(float(raw_input(Please enter a grade: ))) total = sum(value) average = total/target print The average grade that you entered is , (%.2f % average) raw_input(Please hit enter to exit.) ///Can anyone tell me what I am doing wrong on either of these problems? I know it is a logic error, but I am new to this so please bare with me. Again, thanks for your help. I am new to this forum so please have patience with me when I am posting. Thank you, Thomas Mundahl ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and some questions.
On Mon, Sep 29, 2008 at 1:36 AM, [EMAIL PROTECTED] wrote: I did get some help in the python forums with this and I have come up the following, but I am getting a syntax error on the line that calls out total as a variable. Here is the code: The actual problem is in the previous line: print (int(float(raw_input(Please enter a grade, use numbers 1 - 10: ))) If you count, there are 4 (s and 3 )s in there. Because every ( should have a corresponding ) and vice versa, Python thinks that this statement has not finished yet. It gives a syntax error at the _next_ line, because there it finds something that cannot be a correct continuation of this statement. However, even if you would do that, the result would still not be what you want. It will give 0 each time, because value will always be the empty list. Rather than printing out the grade that the user entered, you would want to put it in the list value (an unlucky choice of a name for a list of grades, in my opinion) The next problem is supposed to use the while loop. A user is supposed to enter some grade values. The user will continue to be prompted to enter grade values until the user has entered in as a grade value. Then the program is supposed to calculate the average of all of the grades entered including the . Here is my code, This code is not working either: target = value = [ ] while i in value or not == target: That line will indeed cause Python to stumble. I'm not even sure what you want to do here, so I can't really say what it should have been. -- André Engels, [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and some questions.
[EMAIL PROTECTED] wrote The first problem is a program that will take a list of ten grades from a user and then calculate the average value = [ ] for i in range(10): range += 1 print (int(float(raw_input(Please enter a grade, use numbers 1 - 10: ))) This is very confused. First the range += 1 is going to be wierd because range is a function and you are trying to add one to it! Don't use variable names that are the same as built in functions. Secondly you only need to convert the value to an int. You don't need the float conversion as well. Thirdly, as already pointed out you never assign the value anywhere you just print it. You want to append it to your value list. (Also as a general style point its a good idea to name collections as plurals so use values instead of value - it just reads better) And finally the source of the error, the mismatched parens. Remember Python errors, especially syntax errorts, are often to be found a line or two before where they are reported. The next problem is supposed to use the while loop. A user is supposed to enter some grade values... continue to be prompted to enter grade values until the user has entered in as a grade value. calculate the average of all of the grades entered including the . Really? How bizarre! Here is my code, This code is not working either: target = value = [ ] while i in value or not == target: I have no idea what you intended here. It doesn't read logically as a piece of Python or math or even English... If you remove the sign it might make some sense as English, although not as Python... while i in value or not == target might be translated into Python as while i in value or not i == target or while i in value or i != target But in both cases its wrong since you are testing whether i is in the list of values which is not part of the excercise. It should just be while i != target: where wec assume i is the value input by the user. i += 1 But you don't want to increment i you want to get it from the user, so i = int(raw_input()) Same mistake as before: you are not storing the values entered anywhere. print grade (int(float(raw_input(Please enter a grade: ))) And you haven't assigned anything to grade and you are simply printing the input value rather than storing it in values total = sum(value) average = total/target And this divides the total by even if there are only 2 entries... was supposed to be the magic value used to stop the entry process not a count of how many entries were made. print The average grade that you entered is , (%.2f % average) You need to read up on string formatting too. It should be: print The average grade that you entered is %.2f % average Can anyone tell me what I am doing wrong on either of these problems? I know it is a logic error, but I am new It's more than just logic errors you have some basic syntax issues as well as failing to understand the concepts of variables storing values during processing. print displays but assignment(=) stores. And append() adds to a list... HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello
Hi, I'm in a Python class and we were given the assignment to create our own graphic and my idea was to have a program that asks the user to click six points and then create a circle using the six points they clicked. Once they've done that I want eyes and a mouth to appear in the circle. I was wondering if that was possible or if I need to have them also click the points where the two eyes and nose should appear as well. I have the face written, it looks like this... def main(): winWidth = 200 # give a name to the window width winHeight = 150 #and height win = GraphWin('Face', winWidth, winHeight) # give title and dimensions win.setCoords(0, 0, winWidth, winHeight) # make right side up coordinates! head = Circle(Point(40,100), 25) # set center and radius head.setFill(yellow) head.draw(win) eye1 = Circle(Point(30, 105), 5) eye1.setFill('blue') eye1.draw(win) eye2 = Line(Point(45, 105), Point(55, 105)) # set endpoints eye2.setWidth(3) eye2.draw(win) mouth = Oval(Point(30, 90), Point(50, 85)) # set corners of bounding box mouth.setFill(red) mouth.draw(win) message = Text(Point(winWidth/2, 20), 'Click anywhere to quit.') message.draw(win) win.getMouse() win.close() main() I'm struggling with the Circle, however. This is what I have so far, but it won't work. def main(): winWidth = 300 winHeight = 300 win = GraphWin('Draw a Circle', winWidth, winHeight) win.setCoords(0, 0, winWidth, winHeight) win.setBackground('yellow') message = Text(Point(winWidth/2, 20), 'Click on six points') message.draw(win) # Get and draw six points of circle p1 = win.getMouse() p1.draw(win) p2 = win.getMouse() p2.draw(win) p3 = win.getMouse() p3.draw(win) p4 = win.getMouse() p4.draw(win) p5 = win.getMouse() p5.draw(win) p6 = win.getMouse() p6.draw(win) points = [p1, p2, p3, p4, p5, p6] # Use Oval object to draw the circle Circle = Oval(points) Circle.setFill('green') Circle.setOutline('pink') Circle.setWidth(4) # width of boundary line Circle.draw(win) # Wait for another click to exit message.setText('Click anywhere to quit.') message.setTextColor('red') message.setStyle('italic') message.setSize(20) win.getMouse() win.close() Any advice you have would help out a lot. Thank you for your time. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello
It appears to me that the following line would not work: Circle = Oval(points) The variable points is a list of six points, and I don't know how one would define a circle or oval with 6 points. At the top part of your program, an oval is defined using two points, which makes sense. Maybe you should use two of the points for the outline of the face, one point for each eye, and two for the mouth, which amounts to 6 points total. Greg -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christopher Marlett Sent: Thursday, March 13, 2008 9:55 AM To: tutor@python.org Subject: [Tutor] Hello Hi, I'm in a Python class and we were given the assignment to create our own graphic and my idea was to have a program that asks the user to click six points and then create a circle using the six points they clicked. Once they've done that I want eyes and a mouth to appear in the circle. I was wondering if that was possible or if I need to have them also click the points where the two eyes and nose should appear as well. I have the face written, it looks like this... def main(): winWidth = 200 # give a name to the window width winHeight = 150 #and height win = GraphWin('Face', winWidth, winHeight) # give title and dimensions win.setCoords(0, 0, winWidth, winHeight) # make right side up coordinates! head = Circle(Point(40,100), 25) # set center and radius head.setFill(yellow) head.draw(win) eye1 = Circle(Point(30, 105), 5) eye1.setFill('blue') eye1.draw(win) eye2 = Line(Point(45, 105), Point(55, 105)) # set endpoints eye2.setWidth(3) eye2.draw(win) mouth = Oval(Point(30, 90), Point(50, 85)) # set corners of bounding box mouth.setFill(red) mouth.draw(win) message = Text(Point(winWidth/2, 20), 'Click anywhere to quit.') message.draw(win) win.getMouse() win.close() main() I'm struggling with the Circle, however. This is what I have so far, but it won't work. def main(): winWidth = 300 winHeight = 300 win = GraphWin('Draw a Circle', winWidth, winHeight) win.setCoords(0, 0, winWidth, winHeight) win.setBackground('yellow') message = Text(Point(winWidth/2, 20), 'Click on six points') message.draw(win) # Get and draw six points of circle p1 = win.getMouse() p1.draw(win) p2 = win.getMouse() p2.draw(win) p3 = win.getMouse() p3.draw(win) p4 = win.getMouse() p4.draw(win) p5 = win.getMouse() p5.draw(win) p6 = win.getMouse() p6.draw(win) points = [p1, p2, p3, p4, p5, p6] # Use Oval object to draw the circle Circle = Oval(points) Circle.setFill('green') Circle.setOutline('pink') Circle.setWidth(4) # width of boundary line Circle.draw(win) # Wait for another click to exit message.setText('Click anywhere to quit.') message.setTextColor('red') message.setStyle('italic') message.setSize(20) win.getMouse() win.close() Any advice you have would help out a lot. Thank you for your time. ___ 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] hello can you help me solve this problem
This may be a very broad question but whatever help you could give me would be great. Exercise 2.4.5.1. * Make a program scene.py creating a scene with the graphics methods. You are likely to need to adjust the positions of objects by trial and error until you get the positions you want. Make sure you have graphics.py in the same directory as your program. Exercise 2.4.5.2. * Elaborate your scene program so it becomes changeScene.py, and changes one or more times when you click the mouse (and use win.getMouse()). You may use the position of the mouse click to affect the result, or it may just indicate you are ready to go on to the next view. Also, I don't quite understand how this works. Do you e mail me with your response or is there a website I need to visit to see my question and your response posted? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hello can you help me solve this problem
Christopher Marlett wrote: This may be a very broad question but whatever help you could give me would be great. Exercise 2.4.5.1. * Make a program scene.py creating a scene with the graphics methods. You are likely to need to adjust the positions of objects by trial and error until you get the positions you want. Make sure you have graphics.py in the same directory as your program. Exercise 2.4.5.2. * Elaborate your scene program so it becomes changeScene.py, and changes one or more times when you click the mouse (and use win.getMouse()). You may use the position of the mouse click to affect the result, or it may just indicate you are ready to go on to the next view. We don't offer solutions to homework for many reasons. I assume this is homework. However if you show us a program (or even a program design) you've written and tell us where you are stuck we are glad to help. Also, I don't quite understand how this works. Do you e mail me with your response or is there a website I need to visit to see my question and your response posted? We email you and the tutor list. Please reply to the list not just to the author. -- Bob Gailer 919-636-4239 Chapel Hill, NC ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] hello can you help me solve this problem
Christopher Marlett [EMAIL PROTECTED] wrote Exercise 2.4.5.1. * Make a program scene.py creating a scene with the graphics methods. You are likely to need to adjust the positions of objects by trial and error until you get the positions you want. Make sure you have graphics.py in the same directory as your program. Is this by any chance from the LiveWires tutorial? If so they tend to use a lot of mod8ules that are specific to their course so only folks with LiveWires experience are likely to be able to help. You need to give us some context as to where these come from and where the graphics.py mentioned is found. Its not part of the standard Python library. Also it woyuld be good to tell us what part of the problem you don't understand! The more specific the question the greater the chance of an effective answer. Also, I don't quite understand how this works. Do you email me with your response or is there a website I need to visit to see my question and your response posted? You mail themailing list and the server forwards it to everyone on the list. We Reply All and the list server will forward the reply to you and the list. There are at least 3 web sites where you can read the messages too, but a mail client is usually more powerful and faster. Finally gmane do a news (nntp) feed that you can subscribe to and receivecon your favoured news reader. In my view the best of both worlds! :-) HTH, -- Alan Gauld Author of the Learn to Program web site Temorarily at: http://uk.geocities.com/[EMAIL PROTECTED]/ Normally: http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
I probably won't need to start writing classes but I really want to finish the book before I start coding something. One of the greatest mistakes of my life was to completely finish a programming book before I started coding something. It is why I cannot write a Visual Basic program to this day, even though I read through an absolutely excellent book. I even said to myself, This will totally help me write Visual Basic programs as easily as I write Python programs. So instead, I learned C. Always, always write code as you read a book. If it is a good book/programming language, you should be able to write working programs with increasing complexity as you continue in the book. Also, it is a good idea to periodically go back and observe code that you have written in the past and revise it to better reflect the skills you garner later. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Hello and newbie question about self
Hi guru's, New to the list. I bought O'Reilly's Learning Python (3rd edition for 2.5) a while back. Slowly making my way through it and was pleasantly surprised that Python seems easier than C. Until...I bumped into the self thingy. Can anyone please point me to a document that explains self in layman's terms. Or lacking such a doc throw in a much appreciated layman's explanation what self is and when/where to use it? In the book (so far) I've seen self pop up in these examples (on pages 457 and 458): class C1(C2, C3): def setname(self, who) self.name = who class C1(C2, C3): def __init__(self, who) self.name = who Thanks for any pointers! Regards, Patrick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
In C, you may have objectorientedesque code like the following; struct net { int foo; int bar; int baz; }; void populate_net( struct net* mynet, int fooval, int barval) { mynet-foo = fooval; mynet-bar = barval; mynet -baz = fooval * 5; } int connect_to_net(struct net* mynet) { return open_internet_connection(mynet-foo); } int main (void) { struct net inet; populate_net(inet,2,2); int returncode = connect_to_net(inet); printf(%d\n,returncode); } In that batch of C code, you manipulate the struct without fiddling with its fields in the user code. You let the functions change its values so that they are done correctly. In python, you are doing something similar. However, they make some syntactic sugar to make it so you don't have to pass the object in explicily. That is what self is. So the analgous python code is: class net(object): def __init__(self,fooval,barbal): self.foo = fooval self.bar = barval self.baz = fooval*5 def connect_to(self): return open_internet_connection(self.foo) inet = net(2,2) returncode = inet.connect_to() print returncode See how you don't have to pass in the inet object in? Instead you call it with the inet.connect_to() function, and the object itself is passed in explicitly as self? That's all it is. Btw, make sure to always include self. Otherwise you'll be writing a class method and it doesn't work the same way. --Michael On Feb 3, 2008 3:15 PM, Patrick [EMAIL PROTECTED] wrote: Hi guru's, New to the list. I bought O'Reilly's Learning Python (3rd edition for 2.5) a while back. Slowly making my way through it and was pleasantly surprised that Python seems easier than C. Until...I bumped into the self thingy. Can anyone please point me to a document that explains self in layman's terms. Or lacking such a doc throw in a much appreciated layman's explanation what self is and when/where to use it? In the book (so far) I've seen self pop up in these examples (on pages 457 and 458): class C1(C2, C3): def setname(self, who) self.name = who class C1(C2, C3): def __init__(self, who) self.name = who Thanks for any pointers! Regards, Patrick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
Patrick wrote: Hi guru's, New to the list. I bought O'Reilly's Learning Python (3rd edition for 2.5) a while back. Slowly making my way through it and was pleasantly surprised that Python seems easier than C. Until...I bumped into the self thingy. This should be covered by any tutorial. 2nd edition of Learning Python has a section called Methods that introduces self. Also see http://www.ibiblio.org/swaroopch/byteofpython/read/self.html http://hetland.org/writing/instant-hacking.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
Patrick [EMAIL PROTECTED] wrote Can anyone please point me to a document that explains self in layman's terms. Try the OOP topic inmy tutorial... Or lacking such a doc throw in a much appreciated layman's explanation what self is and when/where to use it? Others have given code samples but a conceptuial explanation is that a) self is only used in OO programming within metjhods of a class. b) self refers to the actual instance of the object receiving the message with caused the method to be invoked. Thus if we have a class C with a method m and 3 instances a,b and z then when we invoke a.m() self will refer to a and when we invoke b.m() self will refer to b. This means that the innards of the method can use self to access the instance specific data for that invocation. If you have used C++ at all you might recognise it as the same as 'this' in C++ except that in Python you must explicitly specify it whereas C++ creates 'this' magically behind the scenes. See my tutorial for more on this under the heading Using classes. If you haven't started writing classes yet, you can safely ignore it for now! -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
Hi Alan, Alan Gauld wrote: Patrick [EMAIL PROTECTED] wrote Can anyone please point me to a document that explains self in layman's terms. Try the OOP topic inmy tutorial... Thanks will have a look. Or lacking such a doc throw in a much appreciated layman's explanation what self is and when/where to use it? Others have given code samples but a conceptuial explanation is that a) self is only used in OO programming within metjhods of a class. Now that really helps. I was wondering about that and this answers it. b) self refers to the actual instance of the object receiving the message with caused the method to be invoked. This and reading chapter 23 in the book makes things much clearer now. Thanks! Thus if we have a class C with a method m and 3 instances a,b and z then when we invoke a.m() self will refer to a and when we invoke b.m() self will refer to b. This means that the innards of the method can use self to access the instance specific data for that invocation. Even more clear now :) If you have used C++ at all you might recognise it as the same as 'this' in C++ except that in Python you must explicitly specify it whereas C++ creates 'this' magically behind the scenes. Last time I used C++ was (iirc) in 1987 with a Borland product. I recall this and remember I got stuck on it then too. See my tutorial for more on this under the heading Using classes. Will do. Thanks for the pointer. If you haven't started writing classes yet, you can safely ignore it for now! I probably won't need to start writing classes but I really want to finish the book before I start coding something. I have a small script I did in (horrible) bash and look forward to try to implement it in (less horrible) Python. Thanks for your help. Regards, Patrick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
Hi Alan, Alan Gauld wrote: Patrick [EMAIL PROTECTED] wrote Can anyone please point me to a document that explains self in layman's terms. Try the OOP topic inmy tutorial... Thanks will have a look. Or lacking such a doc throw in a much appreciated layman's explanation what self is and when/where to use it? Others have given code samples but a conceptuial explanation is that a) self is only used in OO programming within metjhods of a class. Now that really helps. I was wondering about that and this answers it. b) self refers to the actual instance of the object receiving the message with caused the method to be invoked. This and reading chapter 23 in the book makes things much clearer now. Thanks! Thus if we have a class C with a method m and 3 instances a,b and z then when we invoke a.m() self will refer to a and when we invoke b.m() self will refer to b. This means that the innards of the method can use self to access the instance specific data for that invocation. Even more clear now :) If you have used C++ at all you might recognise it as the same as 'this' in C++ except that in Python you must explicitly specify it whereas C++ creates 'this' magically behind the scenes. Last time I used C++ was (iirc) in 1987 with a Borland product. I recall this and remember I got stuck on it then too. See my tutorial for more on this under the heading Using classes. Will do. Thanks for the pointer. If you haven't started writing classes yet, you can safely ignore it for now! I probably won't need to start writing classes but I really want to finish the book before I start coding something. I have a small script I did in (horrible) bash and look forward to try to implement it in (less horrible) Python. Thanks for your help. Regards, Patrick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
Hi Michael, Michael Langford wrote: In C, you may have objectorientedesque code like the following; struct net { int foo; int bar; int baz; }; void populate_net( struct net* mynet, int fooval, int barval) { mynet-foo = fooval; mynet-bar = barval; mynet -baz = fooval * 5; } int connect_to_net(struct net* mynet) { return open_internet_connection(mynet-foo); } int main (void) { struct net inet; populate_net(inet,2,2); int returncode = connect_to_net(inet); printf(%d\n,returncode); } Heh I had to grab my C book and browse up on structs and pointers to get an idea what this was all about :) In that batch of C code, you manipulate the struct without fiddling with its fields in the user code. You let the functions change its values so that they are done correctly. Ok that makes sense. In python, you are doing something similar. However, they make some syntactic sugar to make it so you don't have to pass the object in explicily. That is what self is. Got it. So the analgous python code is: class net(object): def __init__(self,fooval,barbal): self.foo = fooval self.bar = barval self.baz = fooval*5 def connect_to(self): return open_internet_connection(self.foo) inet = net(2,2) returncode = inet.connect_to() print returncode See how you don't have to pass in the inet object in? Instead you call it with the inet.connect_to() function, and the object itself is passed in explicitly as self? Aaah starting to understand now. That's all it is. Btw, make sure to always include self. Otherwise you'll be writing a class method and it doesn't work the same way. Thanks for the elaborate explanation! Regards, Patrick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
Hi Kent, Kent Johnson wrote: Patrick wrote: Hi guru's, New to the list. I bought O'Reilly's Learning Python (3rd edition for 2.5) a while back. Slowly making my way through it and was pleasantly surprised that Python seems easier than C. Until...I bumped into the self thingy. This should be covered by any tutorial. 2nd edition of Learning Python has a section called Methods that introduces self. Also see Yes it does but all was not clear after I finished the first part (chapter 22 in my 3rd edition). Just read chapter 23 and things are clearer now. Luckily the start of chapter 24 mentions that it's no big deal if I didn't understand everything because they will dive deeper into it explaining more. http://www.ibiblio.org/swaroopch/byteofpython/read/self.html http://hetland.org/writing/instant-hacking.html Thanks for the links. Will read them when I have some spare cycles. Regards, Patrick ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hello and newbie question about self
Tony Cappellini wrote: http://www.ibiblio.org/swaroopch/byteofpython/read/self.html Is there a typo in the contents of this web page? Yes, you are right, C++ uses 'this'. Kent Should this statement Note for C++/Java/C# Programmers The self in Python is equivalent to the self pointer in C++ and the this reference in Java and C#. Actually be Note for C++/Java/C# Programmers The self in Python is equivalent to the this pointer in C++ and the this reference in Java and C#. (I substituted this for self) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor