Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Problems using struct pack/unpack in files, and reading them. Date: Sun, 15 Nov 2015 13:23:59 +1100 Lines: 20 Message-ID: References: <20151113192045.GA9913@z-sverige.nu> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <5647e90c$0$1588$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de ZhM6qeZL/7Yla15ZYdShfQbLLu0bcDellRHe0BJv/qmA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'valueerror:': 0.07; 'cc:addr:python-list': 0.09; 'subject:files': 0.09; 'subject:using': 0.09; 'python': 0.10; '1:08': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Problems': 0.16; 'wrote:': 0.16; 'try:': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.30; '15,': 0.30; "i'd": 0.31; "d'aprano": 0.33; 'steven': 0.33; 'except': 0.34; 'handle': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'nov': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'ever': 0.60; 'more': 0.63; 'number:': 0.69; '(also,': 0.84; 'chrisa': 0.84; 'subject:pack': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=p94wDZpWwzbATlirhcw8ejKe2W+blCX+H3Lg9IB9XeQ=; b=vPyWdDxLklsRGGZMQNWHbh9liViluzZd7NjOtkP37kLGSn/dxF3W/GzxjVaBuA5Goh BG5MH2ambMVKoXmwIw8fydeCqMhoRsB0XqjOvUrEhj7/jFC7wwQd3sZ+m5AjDf+Zv58k qD7wQ1ARCloCpvqr1uO28rzWpcmL7mTJi5BGnmM2LDFcpaqTLngt1hZtKTmEeA+Z3jWk hlZiv9miPRmjNkD81KoGMH3wr4/KBbwPUF8HkZfdugR3o9OazDy2GgoYH2O2GclUUB3n RuX8S5HEPjYVQR2cR73W8In4J10Hv+V8dr9ZdUanTXjcvF7qpoJY59RlIdDk/qQzZmhj CWrQ== X-Received: by 10.50.183.11 with SMTP id ei11mr10959995igc.94.1447554239721; Sat, 14 Nov 2015 18:23:59 -0800 (PST) In-Reply-To: <5647e90c$0$1588$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98844 On Sun, Nov 15, 2015 at 1:08 PM, Steven D'Aprano wrote: > number = +raw_input("enter a number: ") > > versus: > > text = raw_input("enter a number: ") > try: > number = float(text) > except ValueError: > number = int(text) What kinds of strings can float() not handle but int() can, and in a program that's going to group floats and ints together as "numbers", will they ever be useful? I'd be more likely to write this as simply: number = float(input("Enter a number: ")) (Also, I use Python 3. No raw. But same diff.) ChrisA