473,569 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSV help required

2 New Member
= 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 ':'
  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

Aug 2 '07 #1
1 1194
6,596 Recognized Expert Expert
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.

Aug 2 '07 #2

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

Similar topics

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 sign of careless user interface design. optparse doesn't prevent you from implementing required options, but doesn't give you much help with it...
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 Studio .Net, where you can see the available database, expand it to get a list of tables, etc. What level of access is required? Of course you need to...
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. Field(myArray(0)): For Each Field in rst.Fields If Field.Attributes And adFldIsNullable Then Required = 0 'field is NOT required Else
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 encoding used in the document, of the version of XML being used... Thanks.
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 particular (required) control as well. However further down the form, there is another control, which has to (under certain conditions) to delete...
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 end-user that must be filled in. I want an error message for each field. The forms are already partially filled in, and a user needs to select which...
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 records. (but on the table, I have these 4 field set up as "Required = No"). I want the codes to be able to check if the 4 fields are null, if is null,...
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 xsd:date element called XYZ_IncDate. <xsd:attribute name="XYZ_IncDate" type="xsd:date" use="required"> If I change the xsd:date element to be...
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 = document.getElementsByTagName("form"); alert(myForm.stateId.value); myForm.removeChild(myForm.stateId);
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 one date after the REQUIRED fields have been populated and totally different date for the NON-REQUIRED fields after they have been populated. It...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.