LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-01-2010, 01:48 PM   #16
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453

Quote:
Originally Posted by ghostdog74 View Post
You are hopelessly misguided. These are not different ways to use a syntax. Not like Perl. So many for loop syntax, so many open() syntax. etc
Of course, not.

In http://www.linuxquestions.org/questi...6/#post4114764 I see:

Code:
for i in range (1, 10):
; in http://www.linuxquestions.org/questi...6/#post4115001 I see:
Code:
for (f1, f2, f3,...fn) in cur:
- quite a different syntax.
 
0 members found this post helpful.
Old 10-01-2010, 02:11 PM   #17
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Original Poster
Rep: Reputation: 63
Quote:
Originally Posted by GrapefruiTgirl View Post
YES ! Thanks Celine ! Your reference has the answer !

Code:
import sys

x= "123.45"
print "row title",
for i in range (1, 10):
  sys.stdout.softspace = 0
  print ";%s" % x,
print
 
Old 10-01-2010, 02:14 PM   #18
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Cool, I'm glad that you found something useful there.

Now if I'm not mistaken, without running that code, it looks to me like it will print a semi-colon at the very beginning of the output. Is this correct? And if so, is that OK?
 
Old 10-01-2010, 03:40 PM   #19
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Original Poster
Rep: Reputation: 63
Yes, it is correct. it will print:
Code:
row title;123,45;123,45;123,45;123,45;123,45;123,45;123,45;123,45;123,45
and this, when loaded in a spreadsheet will draw the "row title" in the column A, the first data in the column B and so on....
 
Old 10-01-2010, 06:32 PM   #20
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Quote:
Originally Posted by Sergei Steshenko View Post
Of course, not.

Code:
for i in range (1, 10):
for (f1, f2, f3,...fn) in cur:[/CODE]

- quite a different syntax.
That syntax is
This is consistent throughout.
Code:
#iterate a list
for i in range(10)

# iterate a file
for n,line in enumerate(open("file"))
There are no other inbuilt syntax for a for loop in Python. you do not see foreach, for var (@something), for(i=0;i<MAX;i++) etc syntaxes as in Perl.
 
Old 10-01-2010, 06:35 PM   #21
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Quote:
Originally Posted by marozsas View Post
I can't use the way you suggested because "x" is not a constant. Just to clarify:
...
(you see now why I reduced the problem in the first place ? If I am using a database, or how the "x" is evaluated it is not important - just "print x," printing a extra space is the problem.)
so why don't you show a sample of the sql output, and how you want to format it?
 
  


Reply

Tags
printing, python, spaces


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
LXer: Review: Programming in Python 3: A Complete Introduction to the Python Language LXer Syndicated Linux News 0 01-26-2009 04:50 AM
Spaces and escaped spaces pslacerda Linux - Newbie 13 12-20-2008 09:03 AM
how to avoid dependencies conflict to install python-imaging-1.1.6-1.rha forshiv Red Hat 4 09-29-2008 08:49 PM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 07:54 PM


All times are GMT -5. The time now is 12:07 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration