Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is pythonic version of scanf() or sscanf() planned?

Reply
Thread Tools

Is pythonic version of scanf() or sscanf() planned?

 
 
Terry Reedy
Guest
Posts: n/a
 
      10-08-2009
ryniek90 wrote:
> On 6 Paź, 06:37, Dennis Lee Bieber <(E-Mail Removed)> wrote:
>> On Sun, 4 Oct 2009 15:48:16 -0700 (PDT), TerryP <(E-Mail Removed)>
>> declaimed the following in gmane.comp.python.general:
>>
>>> In the last 4 years, I have never missed functions like .*scanf() or
>>> atoi().
>>> It's probably a greeaaat thing that Python provides nether as built
>>> ins (per se).

>> Uhm... Isn't the second one spelled "int()" <G>
>> --
>> Wulfraed Dennis Lee Bieber KD6MOG
>> (E-Mail Removed) HTTP://wlfraed.home.netcom.com/

>
>
>
> Ok thanks all for answers. Not counting .split() methods and regexps,
> there's nothing interesting.
> But I remember that lambda function also was unwelcome in Python, but
> finally it is and is doing well. So maybe someone, someday decide to
> put in Python an alternative, really great implementation of scanf() ?


scanf does three things: parses string fields out of text, optionally
converts strings to numbers, and puts the results into pointed-to boxes.
Since Python does not have pointer types, a python function cannot very
well do the last, but has to return the tuple of objects. However, if a
format string has named rather than positional fields, a Python function
could either return a dict or set sttributes on an object. That could be
useful.

If I were doing this, I would look into using the new str.format()
strings rather than %-formatted strings.


 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      10-08-2009
On Thu, 8 Oct 2009 09:33:56 -0700 (PDT), Ben Sizer <(E-Mail Removed)>
declaimed the following in gmane.comp.python.general:

>
> Perhaps struct.unpack is close to what you need? Admittedly that
> doesn't read from a file, but that might not be a problem in most
> cases.
>

I suspect the biggest drawback is that it doesn't do string->numeric
conversions, so one still has to run int(), float(), whatever() on the
fields.

It works great though if one needs to split up fixed-width records
which may not have delimiters, or is working with binary records in
which the data is already numeric.

--
Wulfraed Dennis Lee Bieber KD6MOG
http://www.velocityreviews.com/forums/(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
 
 
 
Joshua Kugler
Guest
Posts: n/a
 
      10-09-2009
ryniek90 wrote:
> So maybe someone, someday decide to
> put in Python an alternative, really great implementation of scanf() ?


My idea of a "great scanf() function" would be a clever combination of
re.match(), int(), and float().

j

 
Reply With Quote
 
TerryP
Guest
Posts: n/a
 
      10-12-2009
On Oct 9, 5:59*pm, Joshua Kugler <(E-Mail Removed)> wrote:
> ryniek90 wrote:
> > So maybe someone, someday decide to
> > put in Python an alternative, really great implementation ofscanf() ?

>
> My idea of a "greatscanf() function" would be a clever combination of
> re.match(), int(), and float().
>
> j


Actually, the Python documentation has something interesting:
http://docs.python.org/3.1/library/r...mulating-scanf
 
Reply With Quote
 
r
Guest
Posts: n/a
 
      10-12-2009
On Oct 3, 8:17*pm, Grant Edwards <(E-Mail Removed)> wrote:
(--snip--)
> One of the fist things I remember being taught as a C progrmmer
> was to never use scanf. *Programs that use scanf tend to fail
> in rather spectacular ways when presented with simple typos and
> other forms of unexpected input. *
>
> Given the bad behavior and general fragility of scanf(), I
> doubt there's much demand for something equally broken for
> Python.


I don't think you can blame scanf() for that. More the "bad behavior"
of humans and "uncanny" ability of human fingers to press the the
wrong damn keys.

 
Reply With Quote
 
Aahz
Guest
Posts: n/a
 
      10-13-2009
In article <(E-Mail Removed)>,
ryniek90 <(E-Mail Removed)> wrote:
>
>But I remember that lambda function also was unwelcome in Python, but
>finally it is and is doing well. So maybe someone, someday decide to
>put in Python an alternative, really great implementation of scanf() ?


How long have you been using Python? lambda has been there almost from
the beginning.
--
Aahz ((E-Mail Removed)) <*> http://www.pythoncraft.com/

"To me vi is Zen. To use vi is to practice zen. Every command is a
koan. Profound to the user, unintelligible to the uninitiated. You
discover truth everytime you use it." (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is pythonic version of scanf() or sscanf() planned? ryniek90 Python 0 10-13-2009 05:58 PM
Re: Where to get stand alone Dot Net Framework version 1.1, version2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? MowGreen [MVP] ASP .Net 5 02-09-2008 01:55 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? PA Bear [MS MVP] ASP .Net 0 02-05-2008 03:28 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? V Green ASP .Net 0 02-05-2008 02:45 AM
Object Oriented vs Pythonic Code, and Pythonic standards Carl J. Van Arsdall Python 4 02-07-2006 10:15 PM



Advertisments