Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46457 > unrolled thread

User Input

Started byEternaltheft <eternaltheft@gmail.com>
First post2013-05-30 04:33 -0700
Last post2013-05-30 16:09 +0100
Articles 19 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 04:33 -0700
    Re: User Input Fábio Santos <fabiosantosart@gmail.com> - 2013-05-30 12:45 +0100
    Re: User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 04:48 -0700
      Re: User Input Chris Angelico <rosuav@gmail.com> - 2013-05-30 22:06 +1000
      Re: User Input MRAB <python@mrabarnett.plus.com> - 2013-05-30 13:08 +0100
      Re: User Input Fábio Santos <fabiosantosart@gmail.com> - 2013-05-30 13:10 +0100
    Re: User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 05:19 -0700
      Re: User Input Fábio Santos <fabiosantosart@gmail.com> - 2013-05-30 13:27 +0100
      Re: User Input Chris Angelico <rosuav@gmail.com> - 2013-05-30 22:28 +1000
    Re: User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 05:37 -0700
      Re: User Input Dave Angel <davea@davea.name> - 2013-05-30 08:58 -0400
      Re: User Input Chris Angelico <rosuav@gmail.com> - 2013-05-30 22:59 +1000
    Re: User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 06:10 -0700
      Re: User Input Dave Angel <davea@davea.name> - 2013-05-30 09:37 -0400
        Re: User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 07:03 -0700
          Re: User Input Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-30 15:30 +0100
            Re: User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 07:49 -0700
        Re: User Input Eternaltheft <eternaltheft@gmail.com> - 2013-05-30 07:47 -0700
          Re: User Input Joshua Landau <joshua.landau.ws@gmail.com> - 2013-05-30 16:09 +0100

#46457 — User Input

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 04:33 -0700
SubjectUser Input
Message-ID<e3fd9fdd-efa0-45b8-97b9-b77519012640@googlegroups.com>
Hi, I'm having trouble oh how prompt the user to enter a file name and how to set up conditions. For example, if there's no file name input by the user, a default is returned

[toc] | [next] | [standalone]


#46459

FromFábio Santos <fabiosantosart@gmail.com>
Date2013-05-30 12:45 +0100
Message-ID<mailman.2406.1369914346.3114.python-list@python.org>
In reply to#46457

[Multipart message — attachments visible in raw view] — view raw

On 30 May 2013 12:42, "Eternaltheft" <eternaltheft@gmail.com> wrote:
>
> Hi, I'm having trouble oh how prompt the user to enter a file name and
how to set up conditions. For example, if there's no file name input by the
user, a default is returned

Are you using raw_input? It returns an empty string if the user enters
nothing, so you can just use an if.

filename = raw_input('file name: ')
if not filename:
    filename = 'your default'

[toc] | [prev] | [next] | [standalone]


#46461

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 04:48 -0700
Message-ID<7f9b7a2e-3142-468b-a2ce-9434c1ad7989@googlegroups.com>
In reply to#46457
On Thursday, May 30, 2013 7:33:41 PM UTC+8, Eternaltheft wrote:
> Hi, I'm having trouble oh how prompt the user to enter a file name and how to set up conditions. For example, if there's no file name input by the user, a default is returned

Thanks for such a fast reply! and no im not using raw input, im just using input. does raw_input work on python 3?

[toc] | [prev] | [next] | [standalone]


#46462

FromChris Angelico <rosuav@gmail.com>
Date2013-05-30 22:06 +1000
Message-ID<mailman.2407.1369915604.3114.python-list@python.org>
In reply to#46461
On Thu, May 30, 2013 at 9:48 PM, Eternaltheft <eternaltheft@gmail.com> wrote:
> On Thursday, May 30, 2013 7:33:41 PM UTC+8, Eternaltheft wrote:
>> Hi, I'm having trouble oh how prompt the user to enter a file name and how to set up conditions. For example, if there's no file name input by the user, a default is returned
>
> Thanks for such a fast reply! and no im not using raw input, im just using input. does raw_input work on python 3?

No, on Python 3 just use input. In Python 2, input() is a dangerous
function that evaluates the entered text and raw_input() is the safe
one; in Python 3, raw_input got renamed to input(). Go ahead and use
input the way Fabio used raw_input.

By the way, there's a handy compact notation for what Fabio wrote:

filename = raw_input('file name: ') or 'your default'

Can be very handy!

ChrisA

[toc] | [prev] | [next] | [standalone]


#46463

FromMRAB <python@mrabarnett.plus.com>
Date2013-05-30 13:08 +0100
Message-ID<mailman.2408.1369915693.3114.python-list@python.org>
In reply to#46461
On 30/05/2013 12:48, Eternaltheft wrote:
> On Thursday, May 30, 2013 7:33:41 PM UTC+8, Eternaltheft wrote:
>> Hi, I'm having trouble oh how prompt the user to enter a file name
>> and how to set up conditions. For example, if there's no file name
>> input by the user, a default is returned
>
> Thanks for such a fast reply! and no im not using raw input, im just
> using input. does raw_input work on python 3?
>
In Python 2 it's called "raw_input" and in Python 3 it's called "input".

Python 2 does have a function called "input", but it's not recommended
(it's dangerous because it's equivalent to "eval(raw_input())", which
will evaluate _whatever_ is entered).

[toc] | [prev] | [next] | [standalone]


#46464

FromFábio Santos <fabiosantosart@gmail.com>
Date2013-05-30 13:10 +0100
Message-ID<mailman.2409.1369916173.3114.python-list@python.org>
In reply to#46461

[Multipart message — attachments visible in raw view] — view raw

On 30 May 2013 12:58, "Eternaltheft" <eternaltheft@gmail.com> wrote:
>
> On Thursday, May 30, 2013 7:33:41 PM UTC+8, Eternaltheft wrote:
> > Hi, I'm having trouble oh how prompt the user to enter a file name and
how to set up conditions. For example, if there's no file name input by the
user, a default is returned
>
> Thanks for such a fast reply! and no im not using raw input, im just
using input. does raw_input work on python 3?

On python 2, the function to prompt the user for input and return a string
is raw_input.

On python 3 that function has been renamed to input.

However on python 2 input is something else. It also evaluates the input as
a python expression. That makes it unsafe to use in most circumstances.

[toc] | [prev] | [next] | [standalone]


#46465

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 05:19 -0700
Message-ID<ccfe68ad-4dbf-4d4f-87ab-5b55d5ca0a26@googlegroups.com>
In reply to#46457
Ok thanks guys. but when i use 

filename = input('file name: ')
if not filename:      #i get filename is not defined
    return(drawBoard) #possible to return function when no file input from user?

[toc] | [prev] | [next] | [standalone]


#46469

FromFábio Santos <fabiosantosart@gmail.com>
Date2013-05-30 13:27 +0100
Message-ID<mailman.2410.1369916858.3114.python-list@python.org>
In reply to#46465

[Multipart message — attachments visible in raw view] — view raw

On 30 May 2013 13:24, "Eternaltheft" <eternaltheft@gmail.com> wrote:
>
> Ok thanks guys. but when i use
>
> filename = input('file name: ')
> if not filename:      #i get filename is not defined
>     return(drawBoard) #possible to return function when no file input
from user?

I don't really understand what you mean. Do you mean that you're getting a
stack trace?

[toc] | [prev] | [next] | [standalone]


#46470

FromChris Angelico <rosuav@gmail.com>
Date2013-05-30 22:28 +1000
Message-ID<mailman.2411.1369916922.3114.python-list@python.org>
In reply to#46465
On Thu, May 30, 2013 at 10:19 PM, Eternaltheft <eternaltheft@gmail.com> wrote:
> Ok thanks guys. but when i use
>
> filename = input('file name: ')
> if not filename:      #i get filename is not defined
>     return(drawBoard) #possible to return function when no file input from user?

Do you really want to return there? What function is this defined in?

I think you probably want what Fabio originally said: that "if not
filename" (which, in this context, means "if the user hit Enter
without typing anything"), assign something to filename.

ChrisA

[toc] | [prev] | [next] | [standalone]


#46474

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 05:37 -0700
Message-ID<864c9d49-9929-43dd-b484-d6be92564cc3@googlegroups.com>
In reply to#46457
sorry about that, i got confused xD. yeah it works good now. 
what i meant to say was can i return a function that i made, if the user inputs nothing?

[toc] | [prev] | [next] | [standalone]


#46483

FromDave Angel <davea@davea.name>
Date2013-05-30 08:58 -0400
Message-ID<mailman.2416.1369918733.3114.python-list@python.org>
In reply to#46474
On 05/30/2013 08:37 AM, Eternaltheft wrote:
> sorry about that, i got confused xD. yeah it works good now.
> what i meant to say was can i return a function that i made, if the user inputs nothing?
>

There wouldn't be anything to stop you.  However, if you have multiple 
returns from the same function, it's usually wise to return the same 
type of information from each of them.  That's why Chris suggested 
simply assigning to filename in the if clause.

But without the whole function, and maybe even a description of what the 
function is expected to do, we can only guess.

Your comments still make no sense to me,

 > filename = input('file name: ')
 > if not filename:      #i get filename is not defined

But filename IS defined, immediately above. If it were undefined, you'd 
not be able to test it here.  Big difference between "not defined" and 
"is empty string".

 >    return(drawBoard) #possible to return function when no file input 
from user?

If drawBoard is a function object, it's certainly possible to return it. 
  But again, without seeing the rest of the function, and maybe how it's 
intended to be used, I can't confirm whether it makes sense.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#46485

FromChris Angelico <rosuav@gmail.com>
Date2013-05-30 22:59 +1000
Message-ID<mailman.2418.1369918785.3114.python-list@python.org>
In reply to#46474
On Thu, May 30, 2013 at 10:37 PM, Eternaltheft <eternaltheft@gmail.com> wrote:
> sorry about that, i got confused xD. yeah it works good now.
> what i meant to say was can i return a function that i made, if the user inputs nothing?

Sure! Anything you want to do, you can do :)

ChrisA

[toc] | [prev] | [next] | [standalone]


#46489

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 06:10 -0700
Message-ID<2eaa39b8-9e87-402a-b0c0-8c8c5d42fed7@googlegroups.com>
In reply to#46457
yeah i found out why it wasn't defined before because i tried to put it into a function. 

this is my drawBoard function: 

import turtle as Turtle
Turtle.title("Checkers")
b = 75

def drawBoard(b):

    Turtle.speed(0)

    Turtle.up()

    Turtle.goto(-4 * b, 4 * b)
    Turtle.down()

    for i in range (8):
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)

    for i in range (1):
        Turtle.right(90)
        Turtle.forward(b*2)
        Turtle.right(90)

    for i in range(8):
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)

    for i in range(1):
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)

    for i in range (8):
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)

    for i in range (1):
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)

    for i in range(8):
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)

    for i in range(1):
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)

    for i in range (8):
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)

    for i in range (1):
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)

    for i in range(8):
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)

    for i in range(1):
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)

    for i in range (8):
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)
        Turtle.left(90)
        Turtle.forward(b)

    for i in range (1):
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)

    for i in range(8):
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)
        Turtle.right(90)
        Turtle.forward(b)


drawBoard(b)

Turtle.done()

it draws an 8x8 board table. 

what i initially wanted to do was to return this function if nothing was inputted from the user. i hope that makes more sense :S

[toc] | [prev] | [next] | [standalone]


#46493

FromDave Angel <davea@davea.name>
Date2013-05-30 09:37 -0400
Message-ID<mailman.2422.1369921090.3114.python-list@python.org>
In reply to#46489
On 05/30/2013 09:10 AM, Eternaltheft wrote:
> yeah i found out why it wasn't defined before because i tried to put it into a function.

That's not a sentence, and it doesn't make sense in any permutation I 
can do on it.

>
> this is my drawBoard function:
>
> import turtle as Turtle
> Turtle.title("Checkers")
> b = 75
>
> def drawBoard(b):
>
>      Turtle.speed(0)
>
>      Turtle.up()
>
>      Turtle.goto(-4 * b, 4 * b)
>      Turtle.down()
>
>      for i in range (8):
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>
>      for i in range (1):
>          Turtle.right(90)
>          Turtle.forward(b*2)
>          Turtle.right(90)
>
>      for i in range(8):
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>
>      for i in range(1):
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>
>      for i in range (8):
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>
>      for i in range (1):
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>
>      for i in range(8):
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>
>      for i in range(1):
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>
>      for i in range (8):
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>
>      for i in range (1):
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>
>      for i in range(8):
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>
>      for i in range(1):
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>
>      for i in range (8):
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>          Turtle.left(90)
>          Turtle.forward(b)
>
>      for i in range (1):
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>
>      for i in range(8):
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>          Turtle.right(90)
>          Turtle.forward(b)
>
>
> drawBoard(b)
>
> Turtle.done()
>
> it draws an 8x8 board table.
>
> what i initially wanted to do was to return this function if nothing was inputted from the user. i hope that makes more sense :S
>

It makes sense if you're also returning a function object when the user 
does have something to say.  But I can't see how you might be doing 
that, unless you're using a lambda to make up a custom function object.

And you still don't show us the function that contains this input 
statement.  Nor how it gets used.  Is the user supposed to supply a 
value for b, and you put it in a variable called filename ?

And perhaps you meant for your function to CALL drawBoard(), rather than 
returning the function object drawBoard.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#46495

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 07:03 -0700
Message-ID<e7509760-32bc-41e5-b27f-bc10d2a4c7d8@googlegroups.com>
In reply to#46493
do you think ti would be better if i call drawBoard?

[toc] | [prev] | [next] | [standalone]


#46496

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-05-30 15:30 +0100
Message-ID<mailman.2423.1369924248.3114.python-list@python.org>
In reply to#46495
On 30/05/2013 15:03, Eternaltheft wrote:
> do you think ti would be better if i call drawBoard?
>

How would I know if you don't quote any context?

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#46500

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 07:49 -0700
Message-ID<a0d568c0-7fdf-4694-9993-717494513f74@googlegroups.com>
In reply to#46496
> And perhaps you meant for your function to CALL drawBoard(), rather than 
> returning the function object drawBoard. 
> DaveA 

do you think it would be better if i call drawBoard? 

[toc] | [prev] | [next] | [standalone]


#46499

FromEternaltheft <eternaltheft@gmail.com>
Date2013-05-30 07:47 -0700
Message-ID<7064d3fc-7641-4ecd-9fe0-9631e949fe72@googlegroups.com>
In reply to#46493
> And perhaps you meant for your function to CALL drawBoard(), rather than 
> 
> returning the function object drawBoard.
> 
> DaveA


do you think it would be better if i call drawBoard?

[toc] | [prev] | [next] | [standalone]


#46501

FromJoshua Landau <joshua.landau.ws@gmail.com>
Date2013-05-30 16:09 +0100
Message-ID<mailman.2426.1369926600.3114.python-list@python.org>
In reply to#46499
On 30 May 2013 15:47, Eternaltheft <eternaltheft@gmail.com> wrote:
>> And perhaps you meant for your function to CALL drawBoard(), rather than
>> returning the function object drawBoard.
>>
>> DaveA
>
> do you think it would be better if i call drawBoard?

Please read http://www.catb.org/esr/faqs/smart-questions.html, or
anything similar you can find.

Start from the beginning.

1) What are you doing? Not "what are you doing now" but, from the top,
what is the goal you are trying to achieve?

2) How have you tried to do it? Code  would be nice here too, but
don't just send really large blocks of irrelevant code. For example, your
"drawBoard" function would be better surmised as:

def drawBoard(b):
    Turtle.speed(0)
    Turtle.up()
    Turtle.goto(-4 * b, 4 * b)
    Turtle.down()

    for i in range (8):
        Turtle.forward(b)
        Turtle.right(90)
        ... # etc, drawing a board

3) What are you stuck on? In this case, you are stuck on what to do
after you call input("stuff"), if I understand. What do you want to do
- not "how do you want to do it" but what is it that you are doing?

4) Finally, we should understand what calling drawBoard is for. Ask us
again and we'll be much more likely to give good answers.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web