Author Topic: raw_input?  (Read 943 times)

0 Members and 1 Guest are viewing this topic.

Offline FiCl

  • Serf
  • *
  • Posts: 25
  • Cookies: -1
    • View Profile
raw_input?
« on: July 08, 2014, 02:43:43 pm »
i ve just started learning Python in which i switched from Java as my first programming language. Ive downloaded Python 2.7, and it took me a while to find out that i have to use raw_input if im going to type something that it isnt a number. I was really confused because the book i was reading had input instead of raw_input. Is there something i am doing wrong? or i have to use raw_input in Python 2.7?

Offline gray-fox

  • Knight
  • **
  • Posts: 208
  • Cookies: 52
    • View Profile
Re: raw_input?
« Reply #1 on: July 08, 2014, 03:04:46 pm »
Your book is most likely python3 book ?
« Last Edit: July 08, 2014, 03:07:31 pm by gray-fox »

Offline FiCl

  • Serf
  • *
  • Posts: 25
  • Cookies: -1
    • View Profile
Re: raw_input?
« Reply #2 on: July 08, 2014, 03:18:06 pm »
doesnt matter... i ve  changed to python 3, but why in python 2.7 you have to use raw_input?

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: raw_input?
« Reply #3 on: July 08, 2014, 03:26:09 pm »
doesnt matter... i ve  changed to python 3, but why in python 2.7 you have to use raw_input?
There's nothing else to use.

Offline FiCl

  • Serf
  • *
  • Posts: 25
  • Cookies: -1
    • View Profile
Re: raw_input?
« Reply #4 on: July 08, 2014, 03:31:40 pm »
There's nothing else to use.
no...i didnt know at first i was using Python 2 so i used input.. It worked, but it allowed me only to enter numbers.

Offline XxCyberTheifxX

  • NULL
  • Posts: 1
  • Cookies: 1
    • View Profile
Re: raw_input?
« Reply #5 on: July 08, 2014, 03:32:53 pm »
Ok, Python was my first language, but coming from Java I can see how this is confusing. In python, input refers to you need the user to input a number, nothing else. raw_input on the other hand, allows them to input a string value, which is more useful if you were foresay, asking their name. Hope this helps!

Offline FiCl

  • Serf
  • *
  • Posts: 25
  • Cookies: -1
    • View Profile
Re: raw_input?
« Reply #6 on: July 08, 2014, 03:34:22 pm »
Ok, Python was my first language, but coming from Java I can see how this is confusing. In python, input refers to you need the user to input a number, nothing else. raw_input on the other hand, allows them to input a string value, which is more useful if you were foresay, asking their name. Hope this helps!
so use input if i know the user will input a number or use raw_input always?

Offline gray-fox

  • Knight
  • **
  • Posts: 208
  • Cookies: 52
    • View Profile
Re: raw_input?
« Reply #7 on: July 08, 2014, 03:37:35 pm »
Ok, Python was my first language, but coming from Java I can see how this is confusing. In python, input refers to you need the user to input a number, nothing else. raw_input on the other hand, allows them to input a string value, which is more useful if you were foresay, asking their name. Hope this helps!
But in Python 3 raw_input( ) is just input(). It was renamed .Right?

Lähetetty minun GT-I9300 laitteesta Tapatalkilla
« Last Edit: July 08, 2014, 03:39:37 pm by gray-fox »

Offline FiCl

  • Serf
  • *
  • Posts: 25
  • Cookies: -1
    • View Profile
Re: raw_input?
« Reply #8 on: July 08, 2014, 03:52:22 pm »
But in Python 3 raw_input( ) is just input(). It was renamed .Right?

Lähetetty minun GT-I9300 laitteesta Tapatalkilla
i dont know, because in Python 2.7 you can use both input and raw_input

Offline TheWormKill

  • EZ's Scripting Whore
  • Global Moderator
  • Knight
  • *
  • Posts: 257
  • Cookies: 66
  • The Grim Reaper of Worms
    • View Profile
Re: raw_input?
« Reply #9 on: July 10, 2014, 06:42:05 pm »
In Python 2.x there are input() (taking only numbers, not recommended to use) and raw_input() (returning string which you can process further). However, Python3 hasn't raw_input, it was renamed to input, since the functionality of the old input can be replaced by a bit more code.
Code: [Select]
try:
     num = int(input('Enter a number: '))
except:
     print('Couldn\'t convert input to Integer!')
Stuff I did: How to think like a superuser, Iridium

He should make that "Haskell"
Quote
<m0rph-is-gay> fuck you thewormkill you python coding mother fucker