Re: [Tutor] I am trying to print list elements but i am getting 'none'
Try giving the print statement outside the for loop On Mon, Oct 10, 2011 at 6:56 PM, Praveen Singh wrote: > This is my code- > def getNumbers(num): > myList=[] > for numbers in range(0,num,2): > print myList.append(numbers) > > > output- > >>> getNumbers(10) > None > None > None > None > None > > Then i find out that list.append doesn't return anything.Then what should i > use for this kind of operation.but if i do something like this on idle's > interpreter it gives me answer- > >>> myList=[] > >>> myList.append(8) > >>> print myList > [8] > > Confused!!! > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need help to learn threading
this one at tutorial point explains multi threading with examples .. http://www.tutorialspoint.com/python/python_multithreading.htm On Sun, Aug 28, 2011 at 9:50 PM, Payal wrote: > Hi all, > Can someone suggest a resource for me to learn threading in python? I > don't know threading in any other language. > I tried a few online tutorials but got lost soon. How do I start? > > With warm regards, > -Payal > -- > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] ValueError
When you take input its bydefault is in string format you might want to typecast and validate teh input On Tue, May 3, 2011 at 4:00 PM, Johnson Tran wrote: > Hi All, > > i am trying to create a program module with two functions (conversion > inches to centimeters then centimeter to inches, I have my program working > although I am trying to adda Value Error function to my program but cannot > seem to it to work: > > > def Conversion(): >print "This program converts the first value from inches to centimeters > and second value centimeters to inches." >print "(1 inch = 2.54 centimeters)" >inches = input("Enter length in inches: ") >centimeters = 2.54 * inches >print "That is", centimeters, "centimeters." > >centimeters = input("Enter length in centimeters: ") >inch = centimeters / 2.54 >print "That is", inch, "inches." > >except ValueError: >print "Invalid digit, please try again." > > Conversion() > > > > Any advice would be great, thanks! > > JT > _______ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help
instead of input ... use raw_input() On Thu, Feb 24, 2011 at 9:45 AM, Chris Schiro wrote: > Hi, > > I am completely new to programming aside from working with basic many years > ago. I purchased a Python book for beginners so I could start from scratch > which has been walking me through just fine until: writing a program to > interact with user for feedback: > > > > name=input(“What is your name? “) > > > > I have found that this line will return an error every time while running > the completed program, unless I enter a number. If I enter a numeric value > the program will continue on as written. > > > > I have followed the code exactly per the book. What is the proper coding in > this scenario? > > > > Thank you, > > > > Chris > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] System Monitoring
We use nagios for all of our monitoring which provides central information for all machines its ok to use shell scripts to do system level monitoring (minimal level) but if you have complex monitoring on java programs and all then use jmax etc Thanks, Nitin On Wed, Feb 9, 2011 at 4:39 PM, de Haan wrote: > Hi, > > Im fairly new to programming in python, and have a question. > > Im looking to build a program that monitor's certain things on my Linux > system. for instance disk space. What is the best way to monitor a Linux > server without using to much resources? > > Should I execute shell commands and grab the output of them? Or should i > use SNMP. Or is there a better way? > > Thanks in advance! > de Haan > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] doing maths on lists
you may want to do type casting whenever you have a float answer cause integer to float causes data loss On Mon, Dec 20, 2010 at 4:28 PM, Chris Begert wrote: > Bonjour > > I have three lists with 65 float items and would like to do the following > sum: > > L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))]) > > So it just should do a sum across all the items in the list: > > L0A[0]*cos(L0B[0]+L0C[0]*JME)+ L0A[1]*cos(L0B[1]+L0C[1]*JME)+... > + L0A[64]*cos(L0B[64]+L0C[64]*JME)= some float number > > > However, I always get this error: > > TypeError: can't multiply sequence by non-int of type 'float' > > I looked it up and there seems to be some solution using either the > "for-in" command or the "map(int,...)" command but I just can't get it to > work > > > Any help will be very much appreciated :) > > Greetings from Sydney > Chris > -- > GRATIS! Movie-FLAT mit über 300 Videos. > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] floats
you have two options 1) either type cast like float_b = float(etcetc) 2) use round method which available inbuilt On Sat, Dec 4, 2010 at 12:22 AM, Christopher Spears wrote: > > I have a float variable that is very long. > > >>> float_a = 1.16667 > > However, I want to pass the value of float_a to float_b, but I want the > float to be accurate to two decimal points. > > >>> float_a = 1.16667 > >>> print "%.2f" % float_a > 1.17 > > I tried the following: > > >>> float_b = "%.2f" % float_a > >>> float_b > '1.17' > >>> type(float_b) > > > This doesn't work because it yields a string. > > Any suggestions? > _______ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Connecting my users
have a look at this http://bytes.com/topic/python/answers/826973-peer-peer-chat-program On Fri, Oct 1, 2010 at 2:49 PM, Timo wrote: > Hello, > > I have the following idea, but no clue how to implement this. > I want my users to be able to connect to other users (with the same > program) and chat with them and exchange files. Ideally without server > interaction. Now I heard about peer-to-peer and bittorrent protocol etc. But > don't know where to start or that I'm even at the right path. > So if anyone can point me into the right direction of a framework or > protocol I should use for this, it would be appreciated. > > Cheers, > Timo > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] iterating over less than a full list
if its a dictionary, then I think you will need to use limit if its normal array you can use range(0,10) and access some_stuff[i] On Sat, Sep 4, 2010 at 10:44 PM, Bill Allen wrote: > Say I have and iterable called some_stuff which is thousands of items in > length and I am looping thru it as such: > > for x in some_stuff > etc... > > However, what if I want only to iterate through only the first ten items of > some_stuff, for testing purposes. Is there a concise way of specifying that > in the for statement line? > > > -Bill > > > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Global name not found, though clearly in use
>From the logs looks like the variable is not initiated when it was used. If I read it correct, you said it down ... that means below the line where the error came? and if they belong to same function then this error is valid Thanks, Nitin On Wed, Jul 14, 2010 at 7:48 PM, Corey Richardson wrote: > Hey tutors. Two separate submissions one day, guess I'm getting busy ;) > > Anyway, I'm re-writing my hangman program to make use of my new-found > understanding of OOP, and using a GUI this time around. I decided on coding > with Tkinter, to get my feet wet with GUI stuff. > Here is the traceback: > > Traceback (most recent call last): > File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__ > return self.func(*args) > File "C:/Users/Corey/Desktop/HangmanApp.py", line 45, in getLetter > self.guess = eWordEntryBox.get() > NameError: global name 'eWordEntryBox' is not defined > > However, not even 30 lines down, (29, to be exact) there is this line: > eWordEntryBox = tk.Entry(fWordEntry) > > Not understanding what is happening here. Same happens when I tack self at > the beginning of it, except it says global name self is not defined. > > Thanks! > ~Corey Richardson > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] I don't understand this code
I tried replying with inline the questions read below within your mail On Tue, Jul 13, 2010 at 8:13 PM, ZUXOXUS wrote: > Hi, > > I am a true beginner in programming, and im learning with > inventwithpython.com. > > There's something I dont understand, and i would really appreciate any > help. > > In chapter 9, the one about the Hangman game, I don't get the block of code > in line 61 > > 59. words = 'ant baboon badger bat bear' > 60. > >1. def getRandomWord(wordList): >2. # This function returns a random string from the passed list of >strings. >3. wordIndex = random.randint(0, len(wordList) - 1) >4. return wordList[wordIndex] > > > The thing is, the "passed list of strings" is called "words", not > "wordList", so I see it shouldn't work. > >> wordList is just a parameter defined for the function and the code which you are showing, it does not call the function anywhere, there should be another line like print getRandomWord(words) > > On the other hand, the variable "wordList" is defined nowhere! > >> You dont have to define the function parameters usually as you can use them as they are appearing. In this case, wordList is parameter to funtion which will be replaced with passed value when the function is called > The code is ok, because the program runs ok. So there is somethings that i > dont get. > > Thank you very much in advance. > > _______ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
Adding to what Andre said, another way of optimizing the problem would be storing the prime number in the range you want to check an array and see if the given number is divisible by any of those prime number This improves the performance. Thanks, nitin On Tue, Jul 13, 2010 at 3:52 PM, Andre Engels wrote: > On Tue, Jul 13, 2010 at 11:50 AM, Dipo Elegbede > wrote: > > I was trying to write a code that prints prime numbers between 1 and 20. > > > > I have by myself seen that something is wrong with my code and also my > > brain. > > > > Could anyone be kind enough to tell me what to do > > > > Where I am confused is how to test for other numbers without one and the > > number itself. It turns out that all numbers pass the condition I set so > > that would presuppose that all numbers are prime which is not. > > > > How exactly can I get it to run checks with other numbers such that it > > doesn't include the number itself and 1. > > > > The code is as follows: > > > > for i in range(1,20): > > > > if float(i) % 1 == 0 and float(i) % i == 0: > > print i, 'is a prime number' > > Your code only checks whether the number divides by 1 and itself. It > should check the numbers in between, and if _any_ divides the number, > decide it is not a prime number. This is best done in a separate > function (note: I am writing it here for clarity of the underlying > algorithm, there are various ways in which it could be made faster, > shorter or more Pythonic): > > def isPrime(n): >divisorFound = False >for i in xrange(2, n): >if n % i == 0: >divisorFound = True >return not divisorFound # divisorFound is true if and only if > there is a number i (1 > for i in range(2,20): >if isPrime(i): > print i, 'is a prime number' > > By the way, do note that your cast to float is not a good idea. It > probably won't hurt you in this case, but it definitely won't improve > things. You'd much rather check exact equality with integers than with > floats. > > -- > André Engels, andreeng...@gmail.com > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
Hi, You have two different problems 1) Easiest algorithm to find a prime number 2) and then coding the algorithm By my knowledge,The Sieve of Eratosthenes algorithm is the fastest to find a prime number. The algorithm works on the basis that if a number n is prime, then all multiples of it are not prime so based on that you can code Thanks, Nitin On Tue, Jul 13, 2010 at 3:20 PM, Dipo Elegbede wrote: > I was trying to write a code that prints prime numbers between 1 and 20. > > I have by myself seen that something is wrong with my code and also my > brain. > > Could anyone be kind enough to tell me what to do > > Where I am confused is how to test for other numbers without one and the > number itself. It turns out that all numbers pass the condition I set so > that would presuppose that all numbers are prime which is not. > > How exactly can I get it to run checks with other numbers such that it > doesn't include the number itself and 1. > > The code is as follows: > > for i in range(1,20): > > if float(i) % 1 == 0 and float(i) % i == 0: > print i, 'is a prime number' > > > -- > Elegbede Muhammed Oladipupo > OCA > +2348077682428 > +2347042171716 > www.dudupay.com > Mobile Banking Solutions | Transaction Processing | Enterprise Application > Development > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- Nitin Pawar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor