Mailing List Archive

cin
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.
cin [ In reply to ]
Joacim L*wgren <fire@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
cin [ In reply to ]
"Joacim Löwgren" <fire@netlimit.com> writes:
| 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.

Think not, in the standard distribution. A few years back someone
contributed a C module (Steve Clift, from Tasmania, 1995), and you can
find it under contrib/Misc on ftp.python.org. Seems to me there may
have been other efforts along these lines, too.

Donn Cave, University Computing Services, University of Washington
donn@u.washington.edu
cin [ In reply to ]
Hi everyone,

"Michael P. Reilly" wrote:
>
> Joacim L*wgren <fire@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
cin [ In reply to ]
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@mikroplan.com.pl

> -----Original Message-----
> From: python-list-admin@python.org
> [mailto:python-list-admin@python.org]On Behalf Of Dr. Peter Stoehr
> Sent: 22 July 1999 21:12
> To: fire@netlimit.com
> Subject: Re: cin
>
>
> Hi everyone,
>
> "Michael P. Reilly" wrote:
> >
> > Joacim L*wgren <fire@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
>
cin [ In reply to ]
On Thu, Jul 22, 1999 at 09:11:44PM +0200, Dr. Peter Stoehr wrote:
>
> # -----------------------------------------
> aString = raw_input("Give me input :")
> print aString
> # -----------------------------------------
>

print raw_input("Give me input :") # This seems much easier!

regards,
Gerrit.