+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" <nou...@nibrahim.net.in> wrote:
> jitendra gupta <jitu.ic...@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@python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to