473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

CSV help required

= OS: XP
= Python v. 2.5

I'm fairly new to all this, so be gentle... ;-)
I've written a small script which strips values from a form and writes them to a CSV (excel-tab). Some of the data I expect to import is in the form of large numbers, which Excel habitually displays as Scientific Notation (not very helpful!)


Expand|Select|Wrap|Line Numbers
  1. linessplit=[s1.split(':',1) for s1 in lines]    # Form Labels end with ':'
  2.  
  3. if(some_condition):
  4.   logfile.write(today)
  5.   logfile.write('\t')
  6.   splitvalues=["'"+x[1].strip() for x in linessplit]   
  7.   logfile.write('\t'.join(["%s" % (v,) for v in splitvalues]))
This works, but all the data is prepacked in single quotes. Not elegant.

I tried
Expand|Select|Wrap|Line Numbers
  1. splitvalues=[str(x[1].strip()) for x in linessplit] 
but Excel doesn't appear to recognise the explicit string conversion. Am I missing something?

The ideal solution would be if users could switch off Scientific Notation display behaviour as a default when starting Excel. (I've looked, but can't see where to do this.)

The next-best thing would be if there were a CSV dialect (excel-nosci) which does the appropriate thing. I don't thing setting QUOTING = ALL *is* appropriate, but I'm willing to be persuaded!

Any help would be warmly welcomed

Simon
Aug 2 '07 #1
1 1189
bartonc
6,596 Expert 4TB
Reading from a file alway yields strings. If that were not the case, .strip() wouldn't work. So there's no need to use str(). I think that the main problem lies within Excel: cell formatting, etc. If Excel has templates, I'd set one up to be the receptacle of your data. When you get it working by hand, Python can even open Excel, load the values and save the file for you.

Tip: Use lots of print statements so that you can see what is going on inside your script.

Also, supply a sample of your data so that we can play around with it.

Thanks.
Aug 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gregory (Grisha) Trubetskoy | last post by:
My humble $0.02: From http://www.python.org/doc/current/lib/optparse-terminology.html: The phrase "required option" is an oxymoron; the presence of "required options" in a program is usually a...
1
by: Bennett Haselton | last post by:
I want to get an ASP.Net hosting account with my ISP, and I'm trying to find out what level of access to the server is requried in order for me to view the server in Server Explorer in Visual...
5
by: Lorenzo Bolognini | last post by:
Hi all, i need to detect whether a field is required or not. I'm using this code for building a string to convert later to an array (by Split) of which each element matches the field index (ex....
6
by: yzzzzz | last post by:
Hi, In which cases is the <?xml version="1.0" encoding="UTF-8"?> processing instruction required at the beginning of an XML document, for the document to be valid? e.g. does it depend on the...
16
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this...
2
by: bufbec1 | last post by:
I am pretty good with Access, but do not understand VBA. I have researched this topic and see only VBA answers, so I hope someone can help with my specific question. I have 2 fields for an...
3
by: Orchid | last post by:
Hello All, Hope someone can help me on my required field problems. I have a form base on a table for users to input new Employees. There are 4 fields that cannot be Null when entering new...
3
by: CindyRob | last post by:
I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix 82202, Visual studio .NET 2003 with hotfix 823639. I have generated a proxy class using wsdl.exe from a schema that has an...
11
by: Naeem | last post by:
I have a Javascript function, which changes a text field of a form into a select field. Following is the function function changeStateField() { var myForm =...
1
by: KMEscherich | last post by:
Hi there, am wondering if there is a way to have this code capture 2 dates. You see, I have several fields and some are REQUIRED fields and some are NON-REQUIRED fields. I am attempting to capture...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.