Wikipedia:Reference desk/Archives/Computing/2012 April 27#Python exception fail

{{#ifeq:{{PAGENAME}}|Special:Undelete| |{{#if:|

}} {{#ifeq:{{NAMESPACE}}|Wikipedia|{{#switch:{{NAMESPACE}}|= |
}}|{{error:not substituted|Archive header}}
}}}} {{#if:|
}}
width = "100%"
colspan="3" align="center" | Computing desk
width="20%" align="left" | < April 26

! width="25%" align="center"|<< Mar | April | May >>

! width="20%" align="right" |{{#ifexist:Wikipedia:Reference desk/Archives/Computing/2012 April 28|April 28|Current desk}} >

align=center width=95% style="background: #FFFFFF; border: 1px solid #003EBA;" cellpadding="8" cellspacing="0"
style="background: #5D7CBA; text-align: center; font-family:Arial; color:#FFFFFF;" | Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is {{#ifexist:Wikipedia:Reference desk/Archives/Computing/2012 May 7|an archive page|a transcluded archive page}}. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.

__TOC__

= April 27 =

MS-Excel

What is MS-Excel? — Preceding unsigned comment added by Aadya mishra (talkcontribs) 05:14, 27 April 2012 (UTC)

: It means Microsoft Excel. Bubba73 You talkin' to me? 05:37, 27 April 2012 (UTC)

iPhone Camcorder/iMovie

Why cannot i import camcorder films from my iPhone into iMovie please?--85.211.154.241 (talk) 05:56, 27 April 2012 (UTC)

:Do any of these links help?[http://www.macworld.com/article/1155619/import_iphone_imovie.html][http://www.mactalk.com.au/31/91319-transfer-video-iphone-4-imovie-mac.html][http://superuser.com/questions/23315/whats-the-easiest-way-to-get-an-iphone-3gs-movie-into-imovie] If not, it would be useful if you told us the particular problem you are having and the version of iMovie and other software you are using. --Colapeninsula (talk) 09:04, 27 April 2012 (UTC)

iPhone3 and iMovie 11.--85.211.154.241 (talk) 15:12, 27 April 2012 (UTC)

Sorry, forgot to thank you for the links, I think that the first one will be helpful. — Preceding unsigned comment added by 85.211.154.241 (talk) 15:18, 27 April 2012 (UTC)

Leading spaces are stripped out of Access table

I am using Access 2007 and importing data from a .csv file into text fields in a table. Some of the text fields have leading spaces which are needed and I want to keep them but Access strips them all out when the data is imported. How can I stop this happening please? Gurumaister (talk) 07:39, 27 April 2012 (UTC)

:Can you put quotation marks around the individual data items, including the leading spaces? Comma-separated values suggests this. --Colapeninsula (talk) 09:10, 27 April 2012 (UTC)

Unfortunately, I can't. The .csv is an export of a name and address file from another (non-Access) database so the data comes out without quotation marks. Surely having leading spaces stripped out should be a matter of choice and therefore optional? I am finding it very frustrating. Gurumaister (talk) 13:22, 27 April 2012 (UTC)

:Access handles all unquoted spaces before data as just ignorable whitespace and ignores it. I don't see any way around that with Access's interface. Your options, as I see them, are 1. Have the other database spit out the data in a quoted fashion, or 2. Put together some kind of CSV pre-processor that adds the quotes in for you automatically. (The latter is only a moderately difficult scripting task, as far as scripting tasks go.) --Mr.98 (talk) 14:27, 27 April 2012 (UTC)

:: This Python script does that (blindly - even elements without whitespace get quoted anyway). It reads stdin and write stdout. -- Finlay McWalterTalk 14:55, 27 April 2012 (UTC)

  1. !/usr/bin/python

import csv,sys

for r in csv.reader(sys.stdin):

for i in range(0,len(r)):

r[i] = '"%s"'%r[i]

print ','.join(r)

:Can you get an intermediate file between database 1 and 2 (this is in line with what 98 talks about as a pre-processor)? Shadowjams (talk) 16:02, 27 April 2012 (UTC)

:Can you predict which fields should have leading white-space? If so you can write an update query in Access that re-adds the whitespaces back in as part of either the import routine or a separate query post import of data. ny156uk (talk) 13:52, 28 April 2012 (UTC)

::Presumably the amount of whitespace varies in an unpredictable way, otherwise it would be a simple workaround to just tack on some whitespace. --Mr.98 (talk) 14:41, 28 April 2012 (UTC)

Python exception fail

{{resolved}}

Why isn't this exception caught?

try:

j = "rgb".index(instring.pop(0))

...

except ValueError,IndexError:

...

Traceback (most recent call last):

File "mug1.py", line 36, in

j = "rgb".index(instring.pop(0))

IndexError: pop from empty list

I tried unpacking the expression:

ch = instring.pop(0)

j = "rgb".index(ch)

but that didn't help.

Tamfang (talk) 19:37, 27 April 2012 (UTC)

:You need parens around ValueError,IndexError to make it a tuple. As it is you're catching ValueError into an object called IndexError. --Sean 19:48, 27 April 2012 (UTC)

:: I see. That's a feature I haven't used much. Thanks! —Tamfang (talk) 00:06, 28 April 2012 (UTC)