Re: [Tutor] Function not using updated variable?

2019-01-21 Thread Alan Gauld via Tutor
On 21/01/2019 00:14, Ello Solcraft wrote: > # currLocation doesn't use the updated variable. > > for x in inputList: > > currCalc.append(x) > currCalc2 = ''.join(currCalc) > currLocation = mapLocation(mapInput(currCalc2))#mapInput(currCalc2)) You haven't hgiven us any inf

Re: [Tutor] Function not using updated variable?

2019-01-20 Thread Steven D'Aprano
Hi Ello, and welcome! On Mon, Jan 21, 2019 at 01:14:55AM +0100, Ello Solcraft wrote: > # currLocation doesn't use the updated variable. How do you know? I'm sorry, but it is impossible for me to tell what is going on here. There simply isn't enough information to understand your code. We don'

[Tutor] Function not using updated variable?

2019-01-20 Thread Ello Solcraft
# currLocation doesn't use the updated variable. for x in inputList: currCalc.append(x) currCalc2 = ''.join(currCalc) currLocation = mapLocation(mapInput(currCalc2))#mapInput(currCalc2)) # I tried printing currCalc2, it updates like it should. But currLocation doesn't use

Re: [Tutor] function question

2019-01-05 Thread Steven D'Aprano
Hello David, and welcome! On Sat, Jan 05, 2019 at 11:18:04AM -0500, David Lynch wrote: [...] > From what I've read about functions I should be able to define a function > with 2 variables? And then I can add all of my code into that function by > indenting it. So far so good! Here's an example

Re: [Tutor] function question

2019-01-05 Thread Alan Gauld via Tutor
On 05/01/2019 16:18, David Lynch wrote: > Hello, > I'm not sure if this is where I can find this sort of help but I am > struggling understanding functions. I have written a simple math code but I > feel like it could be improved if I were to use it in a function. You arein the right place and you

[Tutor] function question

2019-01-05 Thread David Lynch
Hello, I'm not sure if this is where I can find this sort of help but I am struggling understanding functions. I have written a simple math code but I feel like it could be improved if I were to use it in a function. >From what I've read about functions I should be able to define a function with 2

Re: [Tutor] Function question

2017-04-01 Thread Peter O'Doherty
On 25-03-17 11:17, Alan Gauld via Tutor wrote: method: print(' '.join(anotherFunction(4)) Many thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Function question

2017-04-01 Thread Peter O'Doherty
Many thanks! On 25-03-17 11:17, Alan Gauld via Tutor wrote: On 25/03/17 10:01, Peter O'Doherty wrote: def myFunc(num): for i in range(num): print(i) print(myFunc(4)) 0 1 2 3 None #why None here? Because your function does not have an explicit return value so Python returns it

Re: [Tutor] Function question

2017-03-25 Thread Sri Kavi
On Sat, Mar 25, 2017 at 3:31 PM, Peter O'Doherty wrote: > > def myFunc(num): > for i in range(num): > print(i) > > print(myFunc(4)) > 0 > 1 > 2 > 3 > None #why None here? > > Because there are two print() functions, one inside the function and another outside. When a function does not

Re: [Tutor] Function question

2017-03-25 Thread Alan Gauld via Tutor
On 25/03/17 10:01, Peter O'Doherty wrote: > def myFunc(num): > for i in range(num): > print(i) > > print(myFunc(4)) > 0 > 1 > 2 > 3 > None #why None here? Because your function does not have an explicit return value so Python returns its default value - None. So the print() inside

[Tutor] Function question

2017-03-25 Thread Peter O'Doherty
Hi, Apologies for the very basic question but could anyone explain the behaviour of these two functions (in Python3.5)? def myFunc(num): for i in range(num): print(i) print(myFunc(4)) 0 1 2 3 None #why None here? def myFunc(num): for i in range(num): return i print(

Re: [Tutor] Function annotations

2017-02-06 Thread George Fischhof
2017-02-05 9:36 GMT+01:00 Steven D'Aprano : > On Sat, Feb 04, 2017 at 10:11:39PM -0600, boB Stepp wrote: > > > Are the people making linters implementing checking function > > annotations? Or is this something only gradually being adopted? > > Depends which linter :-) > > MyPy is still the refere

Re: [Tutor] Function annotations

2017-02-05 Thread Steven D'Aprano
On Sat, Feb 04, 2017 at 10:11:39PM -0600, boB Stepp wrote: > Are the people making linters implementing checking function > annotations? Or is this something only gradually being adopted? Depends which linter :-) MyPy is still the reference implementation for type hinting in Python: http://myp

Re: [Tutor] Function annotations

2017-02-04 Thread boB Stepp
On Sat, Feb 4, 2017 at 9:23 PM, Steven D'Aprano wrote: > On Sat, Feb 04, 2017 at 08:50:00PM -0600, boB Stepp wrote: >> Of course, these are >> apparently optional. I now wonder if I should be endeavoring to add >> these to my code? > > Do you run a linter? If not, there doesn't seem much point i

Re: [Tutor] Function annotations

2017-02-04 Thread Steven D'Aprano
On Sat, Feb 04, 2017 at 08:50:00PM -0600, boB Stepp wrote: > I just finished looking at > https://docs.python.org/3/tutorial/controlflow.html#function-annotations > and skimming through PEP 484--Type Hints > (https://www.python.org/dev/peps/pep-0484/). My initial impression is > that the purpose o

[Tutor] Function annotations

2017-02-04 Thread boB Stepp
I just finished looking at https://docs.python.org/3/tutorial/controlflow.html#function-annotations and skimming through PEP 484--Type Hints (https://www.python.org/dev/peps/pep-0484/). My initial impression is that the purpose of function annotations is to enable static code analysis tools like l

Re: [Tutor] function argument unpacking

2016-12-08 Thread Danny Yoo
On Thu, Dec 8, 2016 at 1:11 AM, Alan Gauld via Tutor wrote: > On 08/12/16 06:04, Palanikumar wrote: >> #Function Argument unpacking >> def myfunc(x, y, z): >> print(x. v. z) >> > > Please always send the actual code that generates > the error, do not retype as it causes us to chase > phantom

Re: [Tutor] function argument unpacking

2016-12-08 Thread Alan Gauld via Tutor
On 08/12/16 06:04, Palanikumar wrote: > #Function Argument unpacking > def myfunc(x, y, z): > print(x. v. z) > Please always send the actual code that generates the error, do not retype as it causes us to chase phantom bugs. In this case the fact that the v in the print statement should be a

Re: [Tutor] function argument unpacking

2016-12-08 Thread Peter Otten
Palanikumar wrote: > File "func.py", line 8 > tuple_vec = {1, 0, 1) > ^ > SyntaxError: invalid syntax The opening and the closing parenthesis have to match. To get a tuple: tuple_vec = (1, 0, 1) To get a set (with two values in undefined order, so not a good match

[Tutor] function argument unpacking

2016-12-08 Thread Palanikumar
#Function Argument unpacking def myfunc(x, y, z): print(x. v. z) tuple_vec = {1, 0, 1) dict_vec = {'x':1, 'y':0, 'z':1} myfunc(*tuple_vec) myfunc(*dict_vec) It returns following error File "func.py", line 8 tuple_vec = {1, 0, 1) ^ SyntaxError: invalid syntax

Re: [Tutor] Function works one time then subsequently fails

2015-04-29 Thread Alan Gauld
On 29/04/15 04:58, Jim Mooney Py3winXP wrote: numbers = [] Note that you chose to make this global. def parse_string(math_string): """Input: A math string with a verbal or mathematical operation and two valid numbers to operate on. Extra numbers and operations are ignored. Out

Re: [Tutor] Function works one time then subsequently fails

2015-04-28 Thread Cameron Simpson
On 28Apr2015 22:27, Jim Mooney Py3winXP wrote: On 28 April 2015 at 21:27, Cameron Simpson wrote: At a first glance numbers is a global. It is reset to [] at program start, but never again. So you're appending to it forever. I have not investigated further as to how that affects your program's

Re: [Tutor] Function works one time then subsequently fails

2015-04-28 Thread Jim Mooney Py3winXP
On 28 April 2015 at 21:27, Cameron Simpson wrote: > At a first glance numbers is a global. It is reset to [] at program start, > but never again. So you're appending to it forever. I have not investigated > further as to how that affects your program's flow. > > Cheers, > Cameron Simpson > Took

Re: [Tutor] Function works one time then subsequently fails

2015-04-28 Thread Cameron Simpson
On 28Apr2015 20:58, Jim Mooney Py3winXP wrote: This is really puzzling me. I'm parsing a string to do some simple math operations and practice tossing functions around. My parser works on the first run, then it continually fails on the same input. [...] numbers = [] [...] def parse_string(m

[Tutor] Function works one time then subsequently fails

2015-04-28 Thread Jim Mooney Py3winXP
This is really puzzling me. I'm parsing a string to do some simple math operations and practice tossing functions around. My parser works on the first run, then it continually fails on the same input. """ Takes the name of a binary math operation and two numbers from input, repeatedly, and display

Re: [Tutor] Function not returning 05 as string [SOLVED]

2015-04-13 Thread Ken G.
On 04/13/2015 08:56 AM, Steven D'Aprano wrote: On Mon, Apr 13, 2015 at 08:11:46AM -0400, Ken G. wrote: 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: number01 = 0 Here you set the vari

Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Steven D'Aprano
On Mon, Apr 13, 2015 at 08:11:46AM -0400, Ken G. wrote: > 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: > number01 = 0 Here you set the variable "number01" to the int 0. > numberentr

Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread David Palao
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 resul

Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Peter Otten
Ken G. wrote: > 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 > > d

Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Ken G.
On 04/13/2015 08:18 AM, Dave Angel wrote: On 04/13/2015 08:11 AM, Ken G. wrote: 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

Re: [Tutor] Function not returning 05 as string

2015-04-13 Thread Dave Angel
On 04/13/2015 08:11 AM, Ken G. wrote: 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 numb

[Tutor] Function not returning 05 as string

2015-04-13 Thread Ken G.
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

Re: [Tutor] Function help

2014-02-24 Thread Peter Otten
Scott W Dunning wrote: > > On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote: >> If you want to make rows with more or less stars, or stars in other >> colors you could add parameters: >> >> def star_row(numstars, starcolor): >>for i in range(numstars): >>fillstar(sta

Re: [Tutor] Function help

2014-02-24 Thread Alan Gauld
On 24/02/14 02:04, Scott W Dunning wrote: *Also, does anyone know anything about turtle where I can try and move the starting point to the upper left hand corner? * dir() and help() are your friends. After doing dir(turtle) I spooted this likely looking candidate and ran help on it: ---

Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning
On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote: > which still shows a repetetive pattern and thus you can simplify it with > another loop. You should be able to find a way to write that loop with two > star_row() calls on a single iteration, but can you do it with a single call

Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning
On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote: > If you want to make rows with more or less stars, or stars in other colors > you could add parameters: > > def star_row(numstars, starcolor): >for i in range(numstars): >fillstar(starcolor) >space(25) > > Y

Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning
On Feb 23, 2014, at 2:26 AM, Peter Otten <__pete...@web.de> wrote > a programmer would think "for loop” immediately That’s what I thought. It just seemed like way to much to keep repeating everything over and over. I knew there had to be a better way we just haven’t learned loops in school yet.

Re: [Tutor] Function help

2014-02-24 Thread Scott W Dunning
On Feb 23, 2014, at 5:31 AM, Dave Angel wrote: > > Welcome to the tutor forum also, Scott. You'll find it works very > similarly to python-list, and has many of the same people on it. > I'm not sure how you tried to attach source, but please be aware > that this is a text list - anything othe

Re: [Tutor] Function help

2014-02-23 Thread Dave Angel
Scott W Dunning Wrote in message: > I am VERY new to python (programming too). I had a question regarding > functions. Is there a way to call a function multiple times without > recalling it over and over. Meaning is there a way I can call a function and > then add *5 or something like that

Re: [Tutor] Function help

2014-02-23 Thread Ben Finney
Scott W Dunning writes: > I am VERY new to python (programming too). Welcome! You should establish the fundamentals of Python, by working through the Python tutorial http://docs.python.org/3/tutorial/>. Begin at the beginning, and execute all the examples, and experiment with them to satisfy y

Re: [Tutor] Function help

2014-02-23 Thread Peter Otten
Scott W Dunning wrote: > > On Feb 23, 2014, at 1:12 AM, Scott W Dunning wrote: > >> I am VERY new to python (programming too). I had a question regarding >> functions. Is there a way to call a function multiple times without >> recalling it over and over. Meaning is there a way I can call a

Re: [Tutor] Function help

2014-02-23 Thread Scott W Dunning
On Feb 23, 2014, at 1:12 AM, Scott W Dunning wrote: > I am VERY new to python (programming too). I had a question regarding > functions. Is there a way to call a function multiple times without > recalling it over and over. Meaning is there a way I can call a function and > then add *5 or

[Tutor] Function help

2014-02-23 Thread Scott W Dunning
I am VERY new to python (programming too). I had a question regarding functions. Is there a way to call a function multiple times without recalling it over and over. Meaning is there a way I can call a function and then add *5 or something like that? I am trying to code an American Flag usin

Re: [Tutor] Function definition

2013-09-29 Thread Alan Gauld
On 30/09/13 01:13, Sammy Cornet wrote: Greets!! Your help provided to me concerning function definition > was awesome Steven. Gratitude...!!! I'm not sure who's tongue is furthest into their cheek here. But please, in future show us some code and any error messages, it does make it easier to a

Re: [Tutor] Function definition

2013-09-29 Thread Sammy Cornet
Greets!! Your help provided to me concerning function definition was awesome Steven. Gratitude...!!! Sent from my iPhone On Sep 28, 2013, at 9:56, "Steven D'Aprano" wrote: > On Sat, Sep 28, 2013 at 10:19:57AM -0500, Sammy Cornet wrote: >> Hello! >> I'm using python v2.7.5 (IDLE). I'm trying t

Re: [Tutor] Function definition

2013-09-28 Thread Dave Angel
On 28/9/2013 11:19, Sammy Cornet wrote: > Hello! > I'm using python v2.7.5 (IDLE). I'm trying to write a nine_line function that > should use three_lines to print nine blanc lines. For some reason, I only > print one line. Can you please provide me with some explanation? I would be > very grate

Re: [Tutor] Function definition

2013-09-28 Thread Steven D'Aprano
On Sat, Sep 28, 2013 at 10:19:57AM -0500, Sammy Cornet wrote: > Hello! > I'm using python v2.7.5 (IDLE). I'm trying to write a nine_line > function that should use three_lines to print nine blanc lines. For > some reason, I only print one line. Can you please provide me with > some explanation?

[Tutor] Function definition

2013-09-28 Thread Sammy Cornet
Hello! I'm using python v2.7.5 (IDLE). I'm trying to write a nine_line function that should use three_lines to print nine blanc lines. For some reason, I only print one line. Can you please provide me with some explanation? I would be very grateful! __

Re: [Tutor] Function Return Values (or References)

2013-06-24 Thread Steven D'Aprano
On 24/06/13 18:12, John Steedman wrote: Hi Tutors, I'm confused by the following possible contradiction. Would someone please explain or point me to the right docs. [snip confusion about parameter passing and Python's object model] By FACT 1 x should be a reference parameter...? By Fact 2 x

Re: [Tutor] Function Return Values (or References)

2013-06-24 Thread John Steedman
Thanks for all these clear and knowledgeable answers. I'm much clearer on this now and will read up a bit more around these subjects. John On Mon, Jun 24, 2013 at 10:59 AM, Peter Otten <__pete...@web.de> wrote: > John Steedman wrote: > > > Hi Tutors, > > > > I'm confused by the following possi

Re: [Tutor] Function Return Values (or References)

2013-06-24 Thread Peter Otten
John Steedman wrote: > Hi Tutors, > > I'm confused by the following possible contradiction. Would someone please > explain or point me to the right docs. > > FACT 1 > > "Variables in python hold references to objects." > http://en.wikipedia.org/wiki/Python_syntax_and_semantics > > FACT 2 > >>

Re: [Tutor] Function Return Values (or References)

2013-06-24 Thread Dave Angel
On 06/24/2013 04:12 AM, John Steedman wrote: Hi Tutors, I'm confused by the following possible contradiction. Would someone please explain or point me to the right docs. FACT 1 "Variables in python hold references to objects." http://en.wikipedia.org/wiki/Python_syntax_and_semantics FACT 2

[Tutor] Function Return Values (or References)

2013-06-24 Thread John Steedman
Hi Tutors, I'm confused by the following possible contradiction. Would someone please explain or point me to the right docs. FACT 1 "Variables in python hold references to objects." http://en.wikipedia.org/wiki/Python_syntax_and_semantics FACT 2 >>>def Increment ( x ) : >>>// return x + 1

Re: [Tutor] 'function' object has no attribute 'writer'

2011-09-06 Thread Susana Iraiis Delgado Rodriguez
Hello Petter!! Thank you for answer to my question. I apologize for the writing of my code, won't happen again. I added the lines you suggested me, and the script work fine. Than you!! Here's the code corrected and indented. from Tkinter import * #Llamo las librerias graficas de Tk import tkSimple

Re: [Tutor] 'function' object has no attribute 'writer'

2011-09-05 Thread Peter Otten
Susana Iraiis Delgado Rodriguez wrote: Susana, please use 4-space indents for your code samples. I've said it before, but I think it's worthwhile repeating because it makes it much easier to grasp the structure of a script at first sight. > But now I get a differente error, this script is going

Re: [Tutor] 'function' object has no attribute 'writer'

2011-09-05 Thread Susana Iraiis Delgado Rodriguez
Hello guys!!! Shame on me, you're rigth I missunderstood the function and the module. I change the name of my function and that part of my code worked. But now I get a differente error, this script is going to collect information from shapefiles, I asked the user where to start the search, the file

Re: [Tutor] 'function' object has no attribute 'writer'

2011-09-05 Thread Walter Prins
Hi Susana, On 5 September 2011 17:08, Susana Iraiis Delgado Rodriguez < susana.delgad...@utzmg.edu.mx> wrote: > File "win.py", line 43, in boton4 > writer = csv.writer(open(csv_name, 'w')) > AttributeError: 'function' object has no attribute 'writer' > I read a tutorial and csv has a writer

Re: [Tutor] 'function' object has no attribute 'writer'

2011-09-05 Thread James Reynolds
On Mon, Sep 5, 2011 at 12:08 PM, Susana Iraiis Delgado Rodriguez < susana.delgad...@utzmg.edu.mx> wrote: > I want to write a csv file, but I need the final user to give me some > values to open and update the file. My code is: > from Tkinter import * #Llamo las librerias graficas de Tk > import tk

[Tutor] 'function' object has no attribute 'writer'

2011-09-05 Thread Susana Iraiis Delgado Rodriguez
I want to write a csv file, but I need the final user to give me some values to open and update the file. My code is: from Tkinter import * #Llamo las librerias graficas de Tk import tkSimpleDialog #Libreria de almacenamiento de dialogos import tkMessageBox #Libreria de mensajes import tkFileDialog

Re: [Tutor] function remember calls?

2011-08-09 Thread Peter Otten
Robert Johansson wrote: > This is my attempt to generate all pairs of relatively prime pairs of > nonnegative integers (n, m) such that n + m <= N, using the Stern-Brocot > tree. > > def rp_bounded_sum(n, i = 0, p = (0, 1), q = (1, 1), S = set([(0, 1), (1, > 1)])): > # Returns a set S with al

Re: [Tutor] function remember calls?

2011-08-09 Thread Alan Gauld
On 09/08/11 08:44, Robert Johansson wrote: def rp_bounded_sum(n, i = 0, p = (0, 1), q = (1, 1), S = set([(0, 1), (1, 1)])): Strangely, (to me) it seems that the function remembers the set S between different calls: That's correct. Python evaluates the default parameter value once at functi

[Tutor] function remember calls?

2011-08-09 Thread Robert Johansson
Hi all, This is my attempt to generate all pairs of relatively prime pairs of nonnegative integers (n, m) such that n + m <= N, using the Stern-Brocot tree. def rp_bounded_sum(n, i = 0, p = (0, 1), q = (1, 1), S = set([(0, 1), (1, 1)])): # Returns a set S with all relatively prime pairs (a,

Re: [Tutor] function help

2011-02-07 Thread Steven D'Aprano
Ashley F wrote: ok...here's the function I've written so far. def padWithGaps(seq): for letter in seq: letter="-" line=len(seq) dashline=line*letter return dashline I don't think that's a useful function. It seems to do a HUGE amount of work that just keeps get

Re: [Tutor] function help

2011-02-07 Thread James Reynolds
I'm not sure of the answer to your question, because i'm not sure I understand it. Perhaps you could rephrase it? But, there is some other stuff I noticed though: def padWithGaps(seq): for letter in seq: letter="-" line=len(seq) dashline=line*letter return dashli

[Tutor] function help

2011-02-07 Thread Ashley F
ok...here's the function I've written so far.   def padWithGaps(seq):     for letter in seq:    letter="-"    line=len(seq)    dashline=line*letter     return dashline   def replace(someString,position,letter):     first=someString[0:position]     second=letter     third=someString[posi

Re: [Tutor] function error

2010-10-02 Thread ALAN GAULD
> ## > import turtle, random > > def checkForward(distance): > old_position = turtle.position() > turtle._pen.up() > turtle.forward(distance) > forward_failed = outOfBounds() you set forward faile

Re: [Tutor] function error

2010-10-02 Thread roberto
On Sat, Oct 2, 2010 at 7:45 PM, Steve Willoughby wrote: > On 02-Oct-10 10:32, Emile van Sebille wrote: >>> >>> File "my_turtle.py", line 19 >>> if (abs(turtle.position()[0])> turtle.window_height()/2) or >>> ^ >>> SyntaxError: invalid syntax > > How does Python know that the next line is the conti

Re: [Tutor] function error

2010-10-02 Thread Emile van Sebille
On 10/2/2010 10:45 AM Steve Willoughby said... On 02-Oct-10 10:32, Emile van Sebille wrote: Well, not really -- this is the OPs code. I was responding to Joel's comment of not seeing the entire post. File "my_turtle.py", line 19 if (abs(turtle.position()[0]) > turtle.window_height()/2) or

Re: [Tutor] function error

2010-10-02 Thread Steve Willoughby
On 02-Oct-10 10:32, Emile van Sebille wrote: File "my_turtle.py", line 19 if (abs(turtle.position()[0])> turtle.window_height()/2) or ^ SyntaxError: invalid syntax How does Python know that the next line is the continuation of your if statement, instead of the beginning of a new line of code?

Re: [Tutor] function error

2010-10-02 Thread Emile van Sebille
On 10/2/2010 10:16 AM Joel Goldstick said... ## import turtle, random def checkForward(distance): old_position = turtle.position() turtle._pen.up() # no show/hide turtle methods in my turtle modul

Re: [Tutor] function error

2010-10-02 Thread Joel Goldstick
On Sat, Oct 2, 2010 at 12:43 PM, roberto wrote: > On Thu, Sep 30, 2010 at 1:45 PM, ALAN GAULD wrote: >> Copy the code into a text file with a name ending in .py - lets call it >> myfile.py for now >> (if you have not already done so) >> >> From a bash prompt type >> >> $ python myfile.py >> >> Th

Re: [Tutor] function error

2010-10-02 Thread roberto
On Thu, Sep 30, 2010 at 1:45 PM, ALAN GAULD wrote: > Copy the code into a text file with a name ending in .py - lets call it > myfile.py for now > (if you have not already done so) > > From a bash prompt type > > $ python myfile.py > > Then cut n paste any error messages into an email to the list

Re: [Tutor] function error

2010-09-30 Thread ALAN GAULD
ttp://www.alan-g.me.uk/ - Original Message > From: roberto > To: Alan Gauld > Cc: tutor@python.org > Sent: Thursday, 30 September, 2010 10:02:51 > Subject: Re: [Tutor] function error > > On Wed, Sep 29, 2010 at 11:13 PM, Alan Gauld >wrote: > > > >

Re: [Tutor] function error

2010-09-30 Thread roberto
On Wed, Sep 29, 2010 at 11:13 PM, Alan Gauld wrote: > > OK, Thats a non standard error trace so presumably you are running it inside > an IDE of some kind? It may be the IDE is masking the true error. > What happens if you just execute the code from a shell prompt in a console > window?  Can you s

Re: [Tutor] function error

2010-09-29 Thread Alan Gauld
"roberto" wrote Perhaps if you provide the full traceback from the error here it is: TypeError Traceback (most recent call last) ~/randomMove2.py in () > 1 2 3 4 5 ... ~/checkForward.py in out_of_bounds() 19 20 def outOfBo

Re: [Tutor] function error

2010-09-29 Thread Evert Rol
>> Perhaps if you provide the full traceback from the error (assuming you're >> still getting this >error); tracebacks generally show the offending code as >> well. It may be something that's >simply overlooked but shows in the >> traceback. >> >> > > here it is: > > TypeError

Re: [Tutor] function error

2010-09-29 Thread roberto
On Tue, Sep 28, 2010 at 8:26 PM, Evert Rol wrote: > > Perhaps if you provide the full traceback from the error (assuming you're > still getting this >error); tracebacks generally show the offending code as > well. It may be something that's >simply overlooked but shows in the > traceback. > >

Re: [Tutor] function error

2010-09-28 Thread Evert Rol
>> It seems that ur turtle.position doesn't return a list because of this when >> indexing is done on that u get this kind of error. >> --nitin > > it seemed to me that kind of error but then i found that it was a > list, as expected: > > $ type(turtle.position()) > $ > $ abs(turtle.position()[

Re: [Tutor] function error

2010-09-28 Thread roberto
On Tue, Sep 28, 2010 at 12:35 PM, Nitin Das wrote: > It seems that ur turtle.position doesn't return a list because of this when > indexing is done on that u get this kind of error. > --nitin it seemed to me that kind of error but then i found that it was a list, as expected: $ type(turtle.posi

Re: [Tutor] function error

2010-09-28 Thread Nitin Das
It seems that ur turtle.position doesn't return a list because of this when indexing is done on that u get this kind of error. --nitin On Tue, Sep 28, 2010 at 3:39 PM, Alan Gauld wrote: > > "roberto" wrote > > > i have the following error when i call this function: >> 20 def outOfBounds(): >>

Re: [Tutor] function error

2010-09-28 Thread Alan Gauld
"roberto" wrote i have the following error when i call this function: 20 def outOfBounds(): ---> 21 if abs(turtle.position()[0]) > turtle.window_height()/2 or abs(turtle.position()[1]) > turtle.window_width()/2: 22 return "true" 23 else: TypeError: 'f

[Tutor] function error

2010-09-27 Thread roberto
hello, i have the following error when i call this function: 20 def outOfBounds(): ---> 21 if abs(turtle.position()[0]) > turtle.window_height()/2 or abs(turtle.position()[1]) > turtle.window_width()/2: 22 return "true" 23 else: TypeError: 'function' ob

Re: [Tutor] function with multiple checks

2010-09-27 Thread Steven D'Aprano
On Tue, 28 Sep 2010 01:09:54 am Tim Miller wrote: > def complex_password(password): > """Checks password for sufficient complexity.""" > if len(password) < 12: > return False > if len([c for c in password if c in punctuation]) == 0: > return False > if len([c

Re: [Tutor] function with multiple checks

2010-09-27 Thread Tim Miller
On 28/09/10 01:50, Brian Jones wrote: On Mon, Sep 27, 2010 at 11:43 AM, Brian Jones mailto:bkjo...@gmail.com>> wrote: How about this: d = [digits, punctuation, ascii_uppercase, ascii_lowercase] s = 'asdf1234A' for c in d: if not [x for x in s if x in c]: print x, ' not in ', c Ju

Re: [Tutor] function with multiple checks

2010-09-27 Thread Tim Miller
On 28/09/10 01:46, Jerry Hill wrote: The way you've written it obviously works fine. That being said, I'd probably do something like this: from string import ascii_lowercase, ascii_uppercase, digits, punctuation def complex_password(password): '''Checks to make sure a password is complex'

Re: [Tutor] function with multiple checks

2010-09-27 Thread Tim Miller
set does seem to have what you want: isdisjoint() could do the trick. Eg: if set(punctuation).isdisjoint(password) or set(digits).isdisjoint(password) or set(ascii_uppercase).isdisjoint(password) or set(ascii_lowercase).isdisjoint(password): return False return True You co

Re: [Tutor] function with multiple checks

2010-09-27 Thread Evert Rol
> I've got a small function that I'm using to check whether a password is of a > certain length and contains mixed case, numbers and punctuation. > > Originally I was using multiple "if re.search" for the patterns but it looked > terrible so I've read up on list comprehensions and it's slightly

Re: [Tutor] function with multiple checks

2010-09-27 Thread Brian Jones
On Mon, Sep 27, 2010 at 11:43 AM, Brian Jones wrote: > > > On Mon, Sep 27, 2010 at 11:09 AM, Tim Miller wrote: > >> I've got a small function that I'm using to check whether a password is of >> a certain length and contains mixed case, numbers and punctuation. >> >> Originally I was using multip

Re: [Tutor] function with multiple checks

2010-09-27 Thread Jerry Hill
On Mon, Sep 27, 2010 at 11:09 AM, Tim Miller wrote: > I've got a small function that I'm using to check whether a password is of a > certain length and contains mixed case, numbers and punctuation. > > Originally I was using multiple "if re.search" for the patterns but it > looked terrible so I've

Re: [Tutor] function with multiple checks

2010-09-27 Thread Brian Jones
On Mon, Sep 27, 2010 at 11:09 AM, Tim Miller wrote: > I've got a small function that I'm using to check whether a password is of > a certain length and contains mixed case, numbers and punctuation. > > Originally I was using multiple "if re.search" for the patterns but it > looked terrible so I'v

[Tutor] function with multiple checks

2010-09-27 Thread Tim Miller
I've got a small function that I'm using to check whether a password is of a certain length and contains mixed case, numbers and punctuation. Originally I was using multiple "if re.search" for the patterns but it looked terrible so I've read up on list comprehensions and it's slightly improved

Re: [Tutor] Function behavior (SOLVED)

2010-09-17 Thread Ken Green
Thank you. This will be printed out and studied. Amazing of what Python can do. Ken On 09/17/2010 06:10 PM, bob gailer wrote: On 9/16/2010 8:18 AM, Ken Green wrote: I am unclear on the behavior of using a function. Below is a short code I wrote to print an amount out after inputting the n

Re: [Tutor] Function behavior

2010-09-17 Thread bob gailer
On 9/16/2010 8:18 AM, Ken Green wrote: I am unclear on the behavior of using a function. Below is a short code I wrote to print an amount out after inputting the number of match. # TEST Function.py def change(amount): if match == 1: amount = 0 if match == 2: amount =

Re: [Tutor] Function behavior

2010-09-17 Thread Ken Green
Thanks Alan. With suggestion and help from several other people on the list, I was able to solve the problem. I learned from an example previously given. I am using several different tutorials and I have yours bookmarked. Ken On 09/16/2010 05:26 PM, Alan Gauld wrote: "Ken Green" wrote

Re: [Tutor] Function behavior

2010-09-16 Thread Alan Gauld
"Ken Green" wrote I am unclear on the behavior of using a function. You certainly are! Which tutorial are you working from? You have several fundamental errors here, its hard to know where to start. def change(amount): if match == 1: amount = 0 if match == 2: amount

Re: [Tutor] Function behavior

2010-09-16 Thread Evert Rol
> I am unclear on the behavior of using a function. Below is a short code I > wrote to print an amount out after inputting the number of match. > > # TEST Function.py > > def change(amount): >if match == 1: >amount = 0 >if match == 2: >amount = 0 >if match == 3: >

Re: [Tutor] Function behavior

2010-09-16 Thread Viacheslav Chumushuk
On Thu, Sep 16, 2010 at 08:18:45AM -0400, Ken Green wrote: > I am unclear on the behavior of using a function. Below is a short > code I wrote to print an amount out after inputting the number of > match. > > # TEST Function.py > > def change(amount): > if match == 1: > amount = 0

[Tutor] Function behavior

2010-09-16 Thread Ken Green
I am unclear on the behavior of using a function. Below is a short code I wrote to print an amount out after inputting the number of match. # TEST Function.py def change(amount): if match == 1: amount = 0 if match == 2: amount = 0 if match == 3: amount = 3

Re: [Tutor] Function object

2010-09-12 Thread Daniel
What can I say except, thanks so much everyone for taking your time and writing me an explication. I finally understood what function objects are. Thanks, really thanks for helping me out. I wish everyone the best. ___ Tutor maillist - Tutor@python.org

Re: [Tutor] Function object

2010-08-25 Thread Denis Gomes
Daniel, Considering that Python is your first programming language, let's start from the absolute beginning. Before you think about what a function object is, try to understand what a function is. A function is a series of python commands put together under a common heading or name in order

  1   2   >