I'm printing some info into a txt file that will be uploaded into a
MySQL DB. I use ';' as field separaters. How can I stop spaces from
appearing on both sides of the ';'
When I do this:
print >> x,';',object,"; ",AN_string,";" ,ascii,";",sum
My file looks like this:
;12345 ; 23456 ; [1,2,3,4,5] ; 15
I need it to look like this to make the DB happy:
;12345;23456;[1,2,3,4,5];15 6 1513
Brad Tilley wrote: I'm printing some info into a txt file that will be uploaded into a MySQL DB. I use ';' as field separaters. How can I stop spaces from appearing on both sides of the ';'
The spaces are a feature of print. To avoid them, use string formatting
to create a single output string.
print >> x,';',object,"; ",AN_string,";" ,ascii,";",sum
Try
print >> x, ';%s;%s;%s;%s' % (object, AN_string, ascii, sum)
Kent My file looks like this:
;12345 ; 23456 ; [1,2,3,4,5] ; 15
I need it to look like this to make the DB happy:
;12345;23456;[1,2,3,4,5];15
> The spaces are a feature of print. To avoid them, use string formatting to create a single output string.
print >> x,';',object,"; ",AN_string,";" ,ascii,";",sum
Try print >> x, ';%s;%s;%s;%s' % (object, AN_string, ascii, sum)
Kent
or....
print x + ';' + object + ";" + AN_string + ";" + ascii + ";" + sum
On Sunday 07 November 2004 20:02, Brad Tilley wrote: I'm printing some info into a txt file that will be uploaded into a MySQL DB. I use ';' as field separaters. How can I stop spaces from appearing on both sides of the ';'
When I do this:
print >> x,';',object,"; ",AN_string,";" ,ascii,";",sum
My file looks like this:
;12345 ; 23456 ; [1,2,3,4,5] ; 15
I need it to look like this to make the DB happy:
;12345;23456;[1,2,3,4,5];15
Instead of using print, open a file and use the "write" method of the
file object. See the documentation for file objects for more detail.
Dave
Kent Johnson wrote: Brad Tilley wrote:
I'm printing some info into a txt file that will be uploaded into a MySQL DB. I use ';' as field separaters. How can I stop spaces from appearing on both sides of the ';'
The spaces are a feature of print. To avoid them, use string formatting to create a single output string.
print >> x,';',object,"; ",AN_string,";" ,ascii,";",sum
Try print >> x, ';%s;%s;%s;%s' % (object, AN_string, ascii, sum)
Kent
Thanks Kent, this works great.
Kent Johnson wrote: Brad Tilley wrote:
I'm printing some info into a txt file that will be uploaded into a MySQL DB. I use ';' as field separaters. How can I stop spaces from appearing on both sides of the ';'
The spaces are a feature of print. To avoid them, use string formatting to create a single output string.
print >> x,';',object,"; ",AN_string,";" ,ascii,";",sum
Try print >> x, ';%s;%s;%s;%s' % (object, AN_string, ascii, sum)
or even:
print >>x, ';'.join([str(v) for v in (object, AN_string, ascii, sum)])
-Scott David Daniels
Scott.DanielsAc m.Org
On Sunday 07 November 2004 07:02 pm, Brad Tilley wrote: I'm printing some info into a txt file that will be uploaded into a MySQL DB. I use ';' as field separaters. How can I stop spaces from appearing on both sides of the ';'
When I do this:
print >> x,';',object,"; ",AN_string,";" ,ascii,";",sum
My file looks like this:
;12345 ; 23456 ; [1,2,3,4,5] ; 15
I need it to look like this to make the DB happy:
;12345;23456;[1,2,3,4,5];15
Generally speaking, you'll be better off to produce the string
you want and then print it, rather than relying on the print
command's syntax. You'll find it much more intuitive to do
either:
print x+';'+object+"; "+AN_string+";" +ascii+";"+sum
or
print "%s;%s;%s;%s;%s " % (x, object, AN_string, ascii, sum)
In other words, use string operators, then print the result.
Cheers,
Terry
--
Terry Hancock ( hancock at anansispacework s.com )
Anansi Spaceworks http://www.anansispaceworks.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: hokiegal99 |
last post by:
This script works as I expect, except for the last section. I want the
last section to actually remove all spaces from the front and/or end of
filenames. For example, a file that was named " test " would be
renamed "test" (the 2 spaces before and after the filename removed). Any
suggestions on how to do this?
import os, re, string
print...
|
by: Xah Lee |
last post by:
Tabs versus Spaces in Source Code
Xah Lee, 2006-05-13
In coding a computer program, there's often the choices of tabs or
spaces for code indentation. There is a large amount of confusion about
which is better. It has become what's known as “religious war” —
a heated fight over trivia. In this essay, i like to explain what is
the...
|
by: MLH |
last post by:
In an earlier post today, it was mentioned that dbl-spaces
caused alignment-justification problems when printing labels.
I've never noticed this in reports except for those meant for
the production of labels. I routinely embed multiple spaces in
strings - sometimes 3, 4 or 5 to achieve a desired effect in the
printed output. I do it in...
|
by: CC |
last post by:
Hi:
I've conjured up the idea of building a hex line editor as a first real
Python programming exercise.
To begin figuring out how to display a line of data as two-digit hex
bytes, I created a hunk of data then printed it:
ln = '\x00\x01\xFF 456789abcdef'
for i in range(0,15):
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |