[BangPypers] Basic of basic question

Vaidik Kapoor kapoor.vaidik at gmail.com
Wed May 8 14:10:41 CEST 2013


+1

The method explained by Noufal (using try except while trying to convert
input string to int) should be the preferred way of doing what you intend
to do.
On May 8, 2013 5:18 PM, "Noufal Ibrahim" <noufal at nibrahim.net.in> wrote:

> jitendra gupta <jitu.icfai at gmail.com> writes:
>
> >>>> x = input("Enter the nu\t")
> > Enter the nu 3
> >>>> type(x)
> > <type 'int'>
> >>>> x = input("Enter the STR\t")
> > Enter the STR "3"
> >>>> type(x)
> > <type 'str'>
> >>>>
> >
> > Use input(), this will take care of your data type
>
> input is the equivalent of eval(raw_input()). So you get funny things
> like this
>
> >>> input()
> os.listdir("/")
> ['sbin', 'dev', 'mnt', 'etc', 'lost+found', '.ure', '.pulse', 'proc',
> 'sys', 'home', 'media', 'lib64', 'lib', 'opt', 'usr', 'vmlinuz.old',
> 'initrd.img', 'lib32', 'tmp', 'run', 'vmlinuz', 'srv', '.pulse-cookie',
> 'bin', 'petabox', 'selinux', 'root', 'var', 'initrd.img.old', 'boot']
>
> Not the smartest of things to do.
>
> [...]
>
>
> --
> Cordially,
> Noufal
> http://nibrahim.net.in
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list