Re: [Tutor] Help
2016-06-28 7:54 GMT+02:00 Aaron Johnson: > I have a program that is telling my i need your digital snake, but i dont > want a snake. Help > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor I think you have to decide. I see two options: 1) keep obeying your program. That sounds a bit hazardous to me. Consider that the 3 laws of robotics apply to machines not to humans! 2) Ignore your program. You ask for help. My suggestion is: take 2). Best ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Root and power
2015-07-29 5:29 GMT+02:00 Job Hernandez jobrh2...@gmail.com: How is it going tutors? The following problem seems impossible to me: *Write a program that asks the user to enter an integer and prints two integers, root and pwr, such that 0 pwr 6 and root^pwr (root**pwr) is equal to the integer entered by the user. If no such pair of integers exists, it should print a message to that effect*. I would like to solve this problem myself so please don't give me the solution. I need to learn how in the world do find the root and power of an integer that x user entered? I haven been looking on the python website for an appropriate function but I have not. If you have the time can you please tell me about the functions and other facts I need to know in order to solve this problem? Is there a book you guys recommend for total beginners who have no ideal of what computer science and programming is? Thank you, Job ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Hello, First, you need an algorithm that solves your problem. Once you have it, you need to implement it in Python. For the algorithm. Although there are theorems and all sort of smart mathematical tricks you could use, given the conditions you have, have you considered to use a brute force approach? I mean: if all involved numbers are positive you could start testing different values for root from 0 on, and for each value test pwr from 1 to 5 until you find either a solution, something bigger than x. Once you chose the algorithm, for the actual implementation you have to say what part you are blocked at. Best. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Should error checking be duplicated for both functions if one function calls another one?
Hello, Not sure if I got it, but, in my opinion functions should do only one thing.So if function 2 finds an error, it should raise it. There should be another function (function 1 in your case?) taking care of possible raised errors. Best 2015-06-01 16:27 GMT+02:00 boB Stepp robertvst...@gmail.com: Suppose in a given state of a program, function 1 calls function 2. Function 1 includes checks for possible error conditions. If there are no issues, then function 2 should execute with no issues as well. The question is, should function 2 include the error checking done in function 1 if function 2 is only ever called by function 1? My inclination is to say yes, as in some future incarnation of the program function 2 might get called in new ways. What are your thoughts? -- boB ___ 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] Function not returning 05 as string
Hello, In the code that you posted, as it is, you are: 1) defining a function (numberentry) 2) defining a global variable (number01) and setting it to 0 3) calling numberentry discarding the result 4) printing the value of the global variable number01 I would guess that you want to store the result of the function and print it. Is that correct? Best 2015-04-13 14:11 GMT+02:00 Ken G. beachkid...@gmail.com: I am sure there is an simple explanation but when I input 5 (as integer), resulting in 05 (as string), I get zero as the end result. When running the code: START OF PROGRAM: Enter the 1st number: 5 05 0 END OF PROGRAM: START OF CODE: import sys def numberentry(): print number01 = raw_input(Enter the 1st number: ) if number01 == 0: sys.exit() if len(number01) == 1: number01 = 0 + number01 print print number01 return(number01) number01 = 0 numberentry() print print number01 END OF CODE: ___ 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] While truth
Hi, 6, -1 or 0 are not bools (True or False): 6 is True False 0 is False False If you had to design a language and want to think about using numbers in a logical context you could do at least two things: 1) convert the number to bool, ie define a set of rules to assign to each number a logical value, or 2) don't convert and raise an error. In python, like in many other languages, option 1) has been chosen. The rules are roughly: when using a number in a logical context 0 is casted to False, and the other numbers are considered True. The while statement expects an expression that returns a logical value. Put both things together and I think you get your answer, if I well understood. Best 2014-05-20 10:25 GMT+02:00 Ian D dux...@hotmail.com: I was reading a tutorial that had these examples in it: while False: print(False is the new True.) while 6: print(Which numbers are True?) while -1: print(Which numbers are True?) while 0: print(Which numbers are True?) Unfortunately the author never explained these statements. I was wondering if the gist of a while statement could be explained in the context of these examples. e.g. while False: means while True is False, which is never True because True is of course True not False. but while 6: means. err while 6 is True? and this is True because... err. Anyway I am a bit lost with this. Can anyone shed any light please? Thanks. ___ 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] Inheritance in classes
2014-04-08 7:44 GMT+02:00 Santosh Kumar rhce@gmail.com: Can i mask the parent attibutes in the child. let me give a quick example. In [1]: class a: ...: value1 = 1 ...: value2 = 2 ...: In [2]: class b(a): ...: value3 = 3 ...: In [3]: obj1 = b() In [4]: obj1.value1 Out[4]: 1 In [5]: obj1.value2 Out[5]: 2 In [6]: obj1.value3 Out[6]: 3 If you notice in the below example you will see that the child class object ``obj1`` has inherited all the attibutes of the parent class. Is there a way by which i can make the child class not inherit some of the properites of parent class. -- D. Santosh Kumar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Hi, This is the default behaviour. You can ovrcome that, but it will require extra work. For instance you could make use of pseudoprivate attributes (any attribute starting with double underscore, but not ending with dtwo underscores); or some managing attributes tool: *) __getattr__, __getattribute__ are generic ways to manage attribute fetching *) properties and descriptors allow a more specific way to control attributes (one by one) But, be careful. These tools can be very tricky at first. Hope it helps. Best ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help Noob Question
Hello, What do you mean by open it in the interpreter? Do you want to open it and read from it its content? or do you want to execute its python code within the interpreter? Best 2014-03-27 7:43 GMT+01:00 Leo Nardo waterfallr...@gmail.com: Im on windows 8 and i need to open a file called string1.py that is on my desktop, in both the interpreter and notepad++, so that i can work on it. I already have it open in notepad, but for the life of me cannot figure out how to open it in the interpreter. Invalid syntax is the error message when i type in python string1.py into the interpreter! maybe a dumb question but i would appreciate the help for sure. thanks :) ___ 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] When to use multiprocessing Managers?
2014-02-25 11:52 GMT+01:00 James Chapman ja...@uplinkzero.com: Hello tutors I'm curious about managers and when to use them. For example, I see they offer a Queue() for sharing a Q between processes, but if I create a Q in the parent process and pass it down to child processes, then they can put messages into that Q just fine, and I presume the same thing for other objects available under the managers package. So unless the other process is on a different machine, is there a reason to use a manager? Does anyone have any use case examples or snippets I could look at even? Thanks in advance James ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Hello, I asked myself the same question when I started using multiprocessing time ago. So I was very happy when I saw the question by James. From my limited knowledge, I would say that a Manager can be useful when processes are distributed across different hosts, or if the exchange of information between processes is more complex than just a couple of synchronization primitives. Best ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] from command prompt use interactive python and running script together
2014-02-21 15:20 GMT+01:00 Gabriele Brambilla gb.gabrielebrambi...@gmail.com: Hi, Is possible on python to running scripts from the command prompt (I'm using python on windows) and in the end saving all the variables and continue the analysis in the interactive mode? (the one that you activate typing python in the command prompt?) I guess you could define a function that does something like this by using pickle or similar technology. Or to use python in the interactive mode and in some moments to run scripts, without quit() the interactive mode, and use for the script variables the one you have defined in the interactive mode? You could import some objects from modules and use them in the interactive session. thanks Gabriele Best ___ 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] for: how to skip items
Hi Gabriele, Without knowing the details of what you are trying, I guess you could be interested in looking at how to define your own iterators. Regards 2014-02-17 17:05 GMT+01:00 Gabriele Brambilla gb.gabrielebrambi...@gmail.com: Hi, I'm wondering how I can (if I can) make a for loop in which I don't use all the elements. for example a100 = list(range(100)) for a in a100: print(a) it print out to me all the numbers from 0 to 99 But if I want to display only the numbers 0, 9, 19, 29, 39, ...(one every 10 elements) how can I do it WITHOUT defining a new list (my real case is not so simple) and WITHOUT building a list of indexes? thank you Gabriele ___ 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] second if
Also, could you explain better what is your doubt? You don't understand what index = 1 means, or why this if at this point, or anything else? Best 2014-02-07 17:14 GMT+01:00 rahmad akbar matbioi...@gmail.com: he guys, i am trying to understand this code: i understand the first if statement (if line.startswith..) in read_fasta function but couldnt understand the next one(if index =...). thanks in advance!! import sys #class declaration with both attributes we need class Fasta: def __init__(self, name, sequence): #this will store the sequence name self.name = name #this will store the sequence itself self.sequence = sequence #this function will receive the list with the file #contents, create instances of the Fasta class as #it scans the list, putting the sequence name on the #first attribute and the sequence itself on the second #attribute def read_fasta(file): #we declare an empty list that will store all #Fasta class instances generated items = [] index = 0 for line in file: #we check to see if the line starts with a sign if line.startswith(): #if so and our counter is large than 1 #we add the created class instance to our list #a counter larger than 1 means we are reading #from sequences 2 and above if index = 1: items.append(aninstance) index+=1 #we add the line contents to a string name = line[:-1] #and initialize the string to store the sequence seq = '' #this creates a class instance and we add the attributes #which are the strings name and seq aninstance = Fasta(name, seq) else: #the line does not start with so it has to be #a sequence line, so we increment the string and #add it to the created instance seq += line[:-1] aninstance = Fasta(name, seq) #the loop before reads everything but the penultimate #sequence is added at the end, so we need to add it #after the loop ends items.append(aninstance) #a list with all read sequences is returned return items fastafile = open(sys.argv[1], 'r').readlines() mysequences = read_fasta(fastafile) print mysequences for i in mysequences: print i.name -- many thanks mat ___ 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] second if
I guess the replies by Alan and Peter precisely answer to your question? Best 2014-02-10 12:46 GMT+01:00 rahmad akbar matbioi...@gmail.com: David, thanks for your reply. i cant figure out why the if at that point and what is the 'if' try to accompolish On Mon, Feb 10, 2014 at 11:52 AM, David Palao dpalao.pyt...@gmail.com wrote: Also, could you explain better what is your doubt? You don't understand what index = 1 means, or why this if at this point, or anything else? Best 2014-02-07 17:14 GMT+01:00 rahmad akbar matbioi...@gmail.com: he guys, i am trying to understand this code: i understand the first if statement (if line.startswith..) in read_fasta function but couldnt understand the next one(if index =...). thanks in advance!! import sys #class declaration with both attributes we need class Fasta: def __init__(self, name, sequence): #this will store the sequence name self.name = name #this will store the sequence itself self.sequence = sequence #this function will receive the list with the file #contents, create instances of the Fasta class as #it scans the list, putting the sequence name on the #first attribute and the sequence itself on the second #attribute def read_fasta(file): #we declare an empty list that will store all #Fasta class instances generated items = [] index = 0 for line in file: #we check to see if the line starts with a sign if line.startswith(): #if so and our counter is large than 1 #we add the created class instance to our list #a counter larger than 1 means we are reading #from sequences 2 and above if index = 1: items.append(aninstance) index+=1 #we add the line contents to a string name = line[:-1] #and initialize the string to store the sequence seq = '' #this creates a class instance and we add the attributes #which are the strings name and seq aninstance = Fasta(name, seq) else: #the line does not start with so it has to be #a sequence line, so we increment the string and #add it to the created instance seq += line[:-1] aninstance = Fasta(name, seq) #the loop before reads everything but the penultimate #sequence is added at the end, so we need to add it #after the loop ends items.append(aninstance) #a list with all read sequences is returned return items fastafile = open(sys.argv[1], 'r').readlines() mysequences = read_fasta(fastafile) print mysequences for i in mysequences: print i.name -- many thanks mat ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- many thanks mat ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] good django book?
Hi, The Django community has plenty of good information in the web. I would go there and have a look. At least this is what I did, precisely for the same reason that you mention. Best, David 2014-02-06 Christopher Spears cspears2...@yahoo.com: Can anyone recommend a good Django book? I have been looking on Amazon, and the books seem to be out of date. Thanks, Chris ___ 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] Changing only intergers in a list of strings
Hi, Is it not clear to me if you must distinguish ints from other type of numbers, or if, for instances floats and ints must be dealt differently. Anyway, I would propose something like the following function: def FindNumbers(a_string): print You entered:, a_string out_list = [] for item in a_string.split(): try: num = int(item) except ValueError: out_list.append(item) else: out_list.append(%s % (num+a,)) out_string = ' '.join(out_list) # do whatever you want to do with the resulting out_string: return it, or display it... Some comments: 1) I would pass the input string as argument rather than using it as a global. 2) You could use float instead of int to make it more general 3) If you need to distinguish between ints and floats, then you must add a couple of extra lines I hope it helps. Best 2014-02-04 Colin Struthers 303cookiemons...@gmail.com: I am in a beginning python course and am working through some code and I can't even figure out how to start building this particular section of code. My goal is to get a sentence for the user and to take each number in the user string and add 1 to each number. i.e the 4 people had 6 dogs would change to the 5 people had 7 dogs a_string = [ ] int_list = [ ] a_string = raw_input(Enter a sentence with both words and numbers: ) def FindNumbers(): print You entered: , a_string for ints in a_string ...? FindNumbers() I fully understand that this doesn't even begin to work but I don't really know where to start deconstructing the list, editing only the intergers, and joining it all back together. Thanks for the help. -- Colin ___ 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] Changing only intergers in a list of strings
Sorry, there is a typo: (num+a,) should be (num+1,), obviously. 2014-02-05 David Palao dpalao.pyt...@gmail.com: Hi, Is it not clear to me if you must distinguish ints from other type of numbers, or if, for instances floats and ints must be dealt differently. Anyway, I would propose something like the following function: def FindNumbers(a_string): print You entered:, a_string out_list = [] for item in a_string.split(): try: num = int(item) except ValueError: out_list.append(item) else: out_list.append(%s % (num+a,)) out_string = ' '.join(out_list) # do whatever you want to do with the resulting out_string: return it, or display it... Some comments: 1) I would pass the input string as argument rather than using it as a global. 2) You could use float instead of int to make it more general 3) If you need to distinguish between ints and floats, then you must add a couple of extra lines I hope it helps. Best 2014-02-04 Colin Struthers 303cookiemons...@gmail.com: I am in a beginning python course and am working through some code and I can't even figure out how to start building this particular section of code. My goal is to get a sentence for the user and to take each number in the user string and add 1 to each number. i.e the 4 people had 6 dogs would change to the 5 people had 7 dogs a_string = [ ] int_list = [ ] a_string = raw_input(Enter a sentence with both words and numbers: ) def FindNumbers(): print You entered: , a_string for ints in a_string ...? FindNumbers() I fully understand that this doesn't even begin to work but I don't really know where to start deconstructing the list, editing only the intergers, and joining it all back together. Thanks for the help. -- Colin ___ 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] reading files
2014-01-29 Mark Lawrence breamore...@yahoo.co.uk: On 29/01/2014 14:50, Gabriele Brambilla wrote: thanks to everyone, I've used David's method. Gabriele 2014-01-29 Mark Lawrence breamore...@yahoo.co.uk mailto:breamore...@yahoo.co.uk On 29/01/2014 02:09, Gabriele Brambilla wrote: Hi, how could I read float numbers if the data format is like this (using readline): 1.0551951.26758123387023-0.314470329249235 -0.293015360064208 6.157957619078221.92919102133526 13.07804596303782.15175351758512e6 the numbers aren't equally spaced and they had not the same number of figures... thanks Gabriele Something like this, untested:- floats = [] with open('myfile') as infile: for line in infile: floats.extend(float(f) for f in line.split()) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence Please don't top post. FTR what is David's method and who is David? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor I guess he refers to my email, the first answer to his question. Best regards. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: reading files
...that I forgot to send to the mailing list... -- Forwarded message -- From: David Palao dpalao.pyt...@gmail.com Date: 2014-01-29 Subject: Re: [Tutor] reading files To: Gabriele Brambilla gb.gabrielebrambi...@gmail.com Hi, One possibility I can think of: If you make one string with one line of your input, like s = 1.0551951.26758123387023 -0.314470329249235 -0.293015360064208 6.15795761907822 1.92919102133526 13.07804596303782.15175351758512e6 then L = [float(i) for i in s.split()] is a list of the floats you are looking for. Best. 2014-01-29 Gabriele Brambilla gb.gabrielebrambi...@gmail.com: Hi, how could I read float numbers if the data format is like this (using readline): 1.0551951.26758123387023-0.314470329249235 -0.293015360064208 6.157957619078221.92919102133526 13.07804596303782.15175351758512e6 the numbers aren't equally spaced and they had not the same number of figures... thanks Gabriele ___ 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] question about the an exercise in core python programing (including the discription about the exercise)
Hi, some hints: 1) strings are iterables 2) help(zip) 3) help(enumerate) Best regards. 2012/1/4 daedae11 daeda...@126.com ** Who can give me an example program about the exercise 6 in chapter 9 in core python programming ? The exercise is: Write a program that compare the two files given by users. If the two files' content is equal, just print equal. Else, print the rows And column number of the first different position. Thank you! Thank you! -- daedae11 ___ 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