cin

Grzegorz Makarewicz mak at mikroplan.com.pl
Thu Jul 22 18:36:10 EDT 1999


Hi,

Try very old module named sscanf sources in
ftp.python.org/pub/python/contrib/misc/sscanf.c and sscanf.README
#--snip--
import sscanf
fmt='My name is %s and I am %d years old.'
data=('Michael', 30)
result=fmt %data
print result
print sscanf.sscanf(result,fmt)
#/--snip--

output:
My name is Michael and I am 30 years old.
['Michael', 30]

Grzegorz Makarewicz
mak at mikroplan.com.pl

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Dr. Peter Stoehr
> Sent: 22 July 1999 21:12
> To: fire at netlimit.com
> Subject: Re: cin
>
>
> Hi everyone,
>
> "Michael P. Reilly" wrote:
> >
> > Joacim L*wgren <fire at netlimit.com> wrote:
> > : Hi,
> >
> > : I'm new to Python and I'm wondering what the C++ "cin" (or C
> > : "scanf()")equivalent in Python is. Doesn't seem there's a
> quick function for
> > : this.
> >
> > Actually it is not a function, it is an operation (%).
> >
> > >>> name, age = 'Michael', 30
> > >>> s = 'My name is %s and I am %d years old.'
> > >>> print s % (name, age)
> > My name is Michael and I am 30 years old.
> >
> > Take a look at the Library Reference Manual, Section 2.1.5.1
> "More String
> > Operations"
> (http://www.python.org/doc/current/lib/typesseq-strings.html).
> >
> >   -Arcege
>
> this emulates the C-function sprintf and not scanf.
> What Joacim is looking for is something like raw_input :-)
>
> # -----------------------------------------
> aString = raw_input("Give me input :")
> print aString
> # -----------------------------------------
>
> Greetings from Erding/Bavaria/Germany/Europe/Earth/Universe
>     Peter
> --
> ------------------------------------------------------------------
> ---------
>    Dr. Peter Stoehr --- Teisenbergweg 6 --- 85435 Erding --- 08122/47232
> ------------------------------------------------------------------
> ---------
> 		I'm the terror that flaps in the night
>
> --
> http://www.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list