Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming
On Sat, Sep 25, 2010 at 11:50 PM, Preetinder Singh putj...@yahoo.com wrote: Hi I am trying to learn how to program, I want to become a software developer so I can develop a software and also understand how to write my own software not copying someone else. So if there any book or online tutorials for complete beginners. I went to the python website and on wiki python and there are so many books to choose from, please help me choose one. Beginning Python by Magnus lie Hetland is good. I have the first edition, but not the second. I can only imagine that it got better. Head First Programming: A Learner's Guide to Programming Using the Python Language by David Griffiths and Paul Barry was a great read. It's unconventional (by their nature, all Head First books are), but excellent. It's about programming in general, but uses Python to demonstrate. There's also a new book coming out shortly that will probably benefit you: Head First Python. Again, it's unconventional, but thoroughly enjoyable and informative. Disclaimer: I tech reviewed all 3 of these books. I don't get any more $ for you buying them, though. Another great read is the Python Cookbook. You can find the recipes online, also, but sometimes it's good to just sit with a hard copy of the book. The cookbook will walk you through tons of code examples, which is really helpful when you're learning a new language (or any language for the first time). HTH, - jmj ___ 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] I am looking for a book on Beginners who never programmed before or have no experience in programming
On Tue, Sep 28, 2010 at 7:47 AM, Steven D'Aprano st...@pearwood.info wrote: On Tue, 28 Sep 2010 07:37:12 pm Jeremy Jones wrote: Head First Programming: A Learner's Guide to Programming Using the Python Language by David Griffiths and Paul Barry was a great read. It's unconventional (by their nature, all Head First books are), I've never heard of Head First Programming -- how are they unconventional? Both HF Programming (currently out) and HF Python (currently being written) are very example-driven and in the course of each example, introduce a number of concepts. So, rather than having a chapter on lists, the books introduce lists as a part of an evolving example. The conventional approach (in my view) is splitting a book into chapters of such topics as variables, operators, lists, dicts, OO, etc. So, I hope that I conveyed the unconventional as a good thing, because I definitely see it as such. I love these books. Honestly, it's enjoyable to me just to see the craft these folks use to evolve a problem and weave in new concepts all along the way. -- Steven D'Aprano ___ 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] pure function problem
The problem is that your class definition doesn't do anything to explicitly set those attributes. On Thu, Sep 23, 2010 at 4:58 AM, Roelof Wobben rwob...@hotmail.com wrote: snip class tijd : pass You're not doing any explicit setting of attributes at the class level. snip time = tijd() time.hour = 20 time.minutes = 20 time.seconds = 20 You set them on this instance. seconds = 20 uitkomst = tijd() But not on this one. What you probably want to do is something like this: class tijd(object): def __init__(self): self.hour = 20 self.minutes = 20 self.seconds = 20 Or if you prefer to set these when you create the instance, you can pass in values like this: class tijd(object): def __init__(self, hour=20, minutes=20, seconds=20): self.hour = hour self.minutes = minutes self.seconds = seconds I noticed something odd just a sec ago. You have this: uitkomst = tijd() uitkomst = increment(time, seconds) print uitkomst.minutes, uitkomst.seconds You're creating a tijd instance, binding uitkomst to it, then overwriting that instance with what you return from increment(). Anyway, hth. - jmj ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] i know this should be easy
nephish wrote: Hey there, i have a simple question. if something returns a true or false, how do i test for it with an if statement? i am using pygtk with a toggle button that returns TRUE if checked and FALSE if not. do i need quotes around the TRUE / FALSE or should i use 1 and 0? Auto_Tog = self.AutoCheckRaw.get_active() if str(AddDay_Tog)== '1': do so and so. If ``get_active()`` returns True or False (or 1 or 0), you could just do:: if self.AutoCheckRaw.get_active(): do_your_True_stuff_here() else: do_your_False_stuff_here() is this right? thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Jeremy ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Please Help: Hacking
Suranga Sarukkali wrote: Python's Great fro Hacking Right? Please tell me more like when you tell it to a College Student (That tell's What I'm) and since I Sort of new to Programming in Python it's going be easy if done so. Please reply to me at your earliest convenience and by the way General Hacking Education will be Cool since the only hacking I've done is on a Hacking Simulation Game I downloaded yeas ago from http://g1.acid-play.com/download/a599b964/Hackerv1.zip witch got all the tools like Password Crackers Inbuilt to Simulate Hacking Large Company's and making cash from it. You can privately email me on [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] I've been on the Mailing List some time and It's Great! Thanks for the People Developed it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Here you go. This should be enlightening: http://www.catb.org/~esr/writings/unix-koans/script-kiddie.html Jeremy Jones ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Interesting problem
Smith, Jeff wrote: Consider a class with a lt of properties. I would like a member function which generates a dictionary where the keys are the property names and the values are the property values? Is this clear? How might I go about this? Jeff ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Like some object.__dict__? Given this class: 1 class Foo: 2 def __init__(self, **kw): 3 self.__dict__.update(kw) 4 And creating an instance of it like this: In [17]: foo = Foo(**{bar:b, foo:f, bam:bm}) And accessing the properties of it like this: In [18]: foo.foo Out[18]: 'f' In [19]: foo.bar Out[19]: 'b' In [20]: foo.bam Out[20]: 'bm' You can get all properties of it like this: In [21]: foo.__dict__ Out[21]: {'bam': 'bm', 'bar': 'b', 'foo': 'f'} Is this what you're looking for? JJ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Queued threads
Not to beat a dead horse, but Liam Clarke wrote: Oops, you probably want to do this then- for i in range( 0, 3 ): oThread = Thread( target=mainFunction ).start() Thread.start() looks like it returns None. # In [23]: from threading import Thread In [24]: import time In [25]: def foo(): : print doing... : time.sleep(15) : print done : In [26]: t = Thread(target=foo).start() doing... In [27]: print t None In [28]: done In [28]: print t None In [29]: t = Thread(target=foo) In [30]: t.start() doing... In [31]: t.isAlive() Out[31]: True In [32]: done In [32]: t.isAlive() Out[32]: False # So, checking the return of Thread.start() doesn't seem like it would do what you think it would do. You probably want to get the thread object and check that directly with isAlive(). Oh, and if you spawn a bunch of threads at once and you want to wait until the all complete before doing something else, do something like this: # #create a list to contain the threads thread_list = [] for i in range(10): t = Thread(target=foo) print creating thread, t #put each thread in the list thread_list.append(t) #iterate over thread list and start each thread for t in thread_list: print starting thread, t t.start() #iterate over thread list and wait for each thread for t in thread_list: print waiting for thread, t while 1: if not t.isAlive(): break time.sleep(.2) # It'll give you output something like this: # creating thread Thread(Thread-35, initial) creating thread Thread(Thread-36, initial) creating thread Thread(Thread-37, initial) creating thread Thread(Thread-38, initial) creating thread Thread(Thread-39, initial) creating thread Thread(Thread-40, initial) creating thread Thread(Thread-41, initial) creating thread Thread(Thread-42, initial) creating thread Thread(Thread-43, initial) creating thread Thread(Thread-44, initial) starting thread Thread(Thread-35, initial) starting thread Thread(Thread-36, initial) starting thread Thread(Thread-37, initial) starting thread Thread(Thread-38, initial) doing... starting thread Thread(Thread-39, initial) doing... doing... starting thread Thread(Thread-40, initial) doing... starting thread doing... Thread(Thread-41, initial) doing... starting thread Thread(Thread-42, initial) starting thread Thread(Thread-43, initial) starting thread Thread(Thread-44, initial) doing... doing... doing... waiting for thread Thread(Thread-35, started) doing... done done done done done done waiting for thread Thread(Thread-36, stopped) waiting for thread Thread(Thread-37, stopped) waiting for thread done done done done Thread(Thread-38, stopped) waiting for thread Thread(Thread-39, stopped) waiting for thread Thread(Thread-40, stopped) waiting for thread Thread(Thread-41, stopped) waiting for thread Thread(Thread-42, stopped) waiting for thread Thread(Thread-43, stopped) waiting for thread Thread(Thread-44, stopped) # But in this situation, I totally agree with Max. You don't need threads for this. Just use os.system. You could use one of the popens (or the new subprocess module - never used that one myself), but os.system blocks until the called program exits. while oThread: print 'sleeping 3 seconds' time.sleep( 3 ) A if condition generally has an implicit else: pass clause as I think of it, so it will just keep reiterating if the condition isn't met. Jeremy Joens ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with variables
. Sm0kin'_Bull wrote: wrote this, It's a bit lame though I = "Allen" me = "Allen" my = "Allen's" print \ """ %s woke up early in the morning. But, it was unusal by %s. %s pillow was with %s. %s didn't want to wake up But, %s tried my best and woke up. it was so amazing!""" % (I,me,my,me,I,I) raw_input("\n\\t\t\t- The End -") But it looks like this... Allen woke up early in the morning. But, it was unusal by Allen. Allen's pillow was with Allen. Allen didn't want to wake up But, Allen tried my best and woke up. it was so amazing - The End - the problem is about lining I want it to print like this... Allen woke up early in the morning. But, it was unusal by Allen. Allen's pillow was with Allen. Allen didn't want to wake up But, Allen tried my best and woke up. it was so amazing This is what I got: In [45]: I = "Allen" In [46]: me = "Allen" In [47]: my = "Allen's" In [48]: In [48]: print \ : """ : %s woke up early in the morning. But, it was unusal by %s. %s pillow : was with %s. %s didn't want to wake up But, %s tried my best and woke up. : it was so amazing!""" % (I,me,my,me,I,I) Allen woke up early in the morning. But, it was unusal by Allen. Allen's pillow was with Allen. Allen didn't want to wake up But, Allen tried my best and woke up. it was so amazing! It looks like it should. If you want it to show up exactly like posted at the end, you need something more like this: In [50]: print \ : """ : %s woke up early in the morning. But, it was unusal by %s. : %s pillow was with %s. %s didn't want to wake up But, %s : tried my best and woke up. it was so amazing!""" % (I,me,my,me,I,I) Allen woke up early in the morning. But, it was unusal by Allen. Allen's pillow was with Allen. Allen didn't want to wake up But, Allen tried my best and woke up. it was so amazing! ### Jeremy Jones FREE pop-up blocking with the new MSN Toolbar MSN Toolbar Get it now! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] count words
Ron Nixon wrote: I know that you can do this to get a count of home many times a word appears in a file f = open('text.txt').read() print f.count('word') Other than using a several print statments to look for seperate words like this, is there a way to do it so that I get a individual count of each word: word1 xxx word2 xxx words xxx etc. Like this? A 14 AND 1 Abantes 3 Abarbarea 1 Abas 1 Abians 1 Ablerus 1 About 2 Abydos 3 Acamas 11 Accept 2 Acessamenus 1 Achaea 1 Achaean 34 Achaeans 540 Achelous 2 Achilles 423 Acrisius 1 Actaea 1 Actor 8 Adamas 5 Admetus 4 Adrastus 2 Adresteia 1 Adrestus 8 Aeacus 20 Aegae 2 Aegaeon 1 Aegeus 1 Aegialeia 1 Aegialus 1 Aegilips 1 Aegina 1 Aegium 1 Aeneas 86 Aenus 1 Aeolus 1 Aepea 2 Aepytus 1 Aesculapius 7 Aesepus 2 Aesopus 4 Aesyetes 2 Aesyme 1 Aesymnus 1 ... wronged 2 wronging 1 wrongs 1 wroth 1 wrought 24 wrung 1 yard 3 yarded 1 yards 2 yawned 1 ye 3 yea 1 year 13 yearling 2 yearned 4 yearning 2 years 15 yellow 5 yesterday 5 yet 160 yield 10 yielded 3 yielding 3 yieldit 1 yoke 24 yoked 11 yokes 1 yokestraps 1 yolking 1 yonder 3 you 1712 young 44 younger 9 youngest 6 your 592 yourelf 1 yours 7 yourself 60 yourselves 17 youselves 1 youth 17 youths 18 zeal 2 I ran the following script on "The Iliad": #!/usr/bin/env python import string text = open('iliad.txt', 'r').read() for punct in string.punctuation: text = text.replace(punct, ' ') words = text.split() word_dict = {} for word in words: word_dict[word] = word_dict.get(word, 0) + 1 word_list = word_dict.keys() word_list.sort() for word in word_list: print "%-25s%d" % (word, word_dict[word]) Jeremy Jones ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor