Need help converting text to csv format

J

John Machin

No, only to those which is blatantly obvious that they didn't put any
effort whatsoever to find an answer on their own; "python csv" has
1,420,000 hits in Google, the first one linking to the csv module
docs.

If I had to write such a script in Python, I'd be using the re and csv
modules in similar fashion to responses already posted. If I had to
write it in PHP, it'd be my first PHP script, so let's go Googling:

google("php regex") first hit:
http://www.regular-expressions.info/php.html
[yuk, 3 different toolkits; 3rd is PCRE, let's try that]

google("php csv") 3rd hit points to:
http://www.php.net/manual/en/function.fputcsv.php

Doesn't seem too difficult to me.

I'd be interested to hear from the OP what is his level of experience
in PHP, how he would have approached the problem in PHP, and why he
didn't look for similar ways in Python.
 
R

r0g

<snip>


John said:
If I had to write such a script in Python, I'd be using the re and csv
modules in similar fashion to responses already posted. If I had to
write it in PHP, it'd be my first PHP script, so let's go Googling:

google("php regex") first hit:
http://www.regular-expressions.info/php.html
[yuk, 3 different toolkits; 3rd is PCRE, let's try that]

google("php csv") 3rd hit points to:
http://www.php.net/manual/en/function.fputcsv.php

Doesn't seem too difficult to me.

I'm sure it doesn't, it doesn't to me either, but only because we
already know what he needs! Do you think if the OP knew all about
regular expressions and understood that python has a handy csv module
that he'd be asking this question here?

The OP is used to PHP, a fairly different kettle of fish. Disgusting
though PHP is it is many peoples first programming language, often in
the unpleasant form of mod_php on a web server - clearly we are not
dealing with a linux kernel hacker here.

I don't think it's at all unreasonable to come here and ask for "help,
pseudo code, or whatever push in the right direction", and I certainly
don't see a need to start questioning his credentails.

He needs to know about the re and csv modules. A minimal yet polite
response might have been: Go and google for the re and csv modules. You
could have typed that, saved yourself a few hundred keystrokes and
helped someone in the process.

If you can't muster even that level of enthusiasm or courtesy towards
the noobs then you always have the option of not responding.

:-/

Roger.
 
A

alex23

A follow-up question here... is it really necessary to close things  
like files in Python?

Not if you use a context manager (2.6+, available in 2.5 from
__future__):

with open('data.csv', 'wb') as csvfile:
writer = csv.writer(csvfile)
...

The file is guaranteed to be closed at the end of the with-statement
block.
 
J

John Machin

<snip>

John said:
If I had to write such a script in Python, I'd be using the re and csv
modules in similar fashion to responses already posted. If I had to
write it in PHP, it'd be my first PHP script, so let's go Googling:
google("php regex") first hit:
http://www.regular-expressions.info/php.html
[yuk, 3 different toolkits; 3rd is PCRE, let's try that]
Doesn't seem too difficult to me.

I'm sure it doesn't, it doesn't to me either, but only because we
already know what he needs! Do you think if the OP knew all about
regular expressions and understood that python has a handy csv module
that he'd be asking this question here?

(1) csv: The OP already knows what "csv" means -- see the subject
heading. Therefore expecting him to google("python csv") or something
similar before asking is quite reasonable.

(2) re: I don't and didn't expect the OP to "know all about regular
expressions". I did expect the OP to know that regular expressions
exist, based on the observations (a) many noobs seem to know a lot
about regular expressions [but don't know that they are not the best
option for parsing HTML and XML] (b) the OP stated "I do have a good
bit of PHP programming experience". Again, googling "python regular
expressions" or similar is a reasonable expectation.
The OP is used to PHP, a fairly different kettle of fish. > Disgusting
though PHP is it is many peoples first programming language, often in
the unpleasant form of mod_php on a web server - clearly we are not
dealing with a linux kernel hacker here.

Is a "linux kernel hacker" some superior form of being?
I don't think it's at all unreasonable to come here and ask for "help,
pseudo code, or whatever push in the right direction", and I certainly
don't see a need to start questioning his credentails.

Possibly you meant "self reliance", not "credentials".
He needs to know about the re and csv modules. A minimal yet polite
response might have been: Go and google for the re and csv modules. You
could have typed that, saved yourself a few hundred keystrokes and
helped someone in the process.

By the time I replied, the OP had already been well and truly spoon-
fed far beyond that level. I was merely concurring with George's
"blatantly obvious that they didn't put any effort whatsoever to find
an answer on their own" proposition.
If you can't muster even that level of enthusiasm or courtesy towards
the noobs then you always have the option of not responding.

Your "if X then Y" logic is somewhat cockeyed -- Y is true independent
of X. Looking just at X: read some of my posts. You may find some with
a reasonable level of enthusiam and courtesy, especially where the
enquirer appears to have helped themselves to a reasonable extent
first and/or are having ESL difficulties and/or have not had a
response after 12 hours or more ...
 
S

Steve Holden

John said:
On Nov 22, 11:04 am, r0g <[email protected]> wrote:
[...]>> If you can't muster even that level of enthusiasm or courtesy
towards
Your "if X then Y" logic is somewhat cockeyed -- Y is true independent
of X. Looking just at X: read some of my posts. You may find some with
a reasonable level of enthusiam and courtesy, especially where the
enquirer appears to have helped themselves to a reasonable extent
first and/or are having ESL difficulties and/or have not had a
response after 12 hours or more ...
John, you are an industrious and courteous helper on this list, no doubt
about it. I didn't mean to start a long debate about all this, I merely
wanted to point out that since noobs *will* often post without trying to
solve their own problem it's best to just ignore them if you don't feel
like answering.

If nobody takes pity on the questioner it will eventually be obvious
that some further access to one's own resources is necessary.

regards
Steve
 
S

Steve Holden

John said:
On Nov 22, 11:04 am, r0g <[email protected]> wrote:
[...]>> If you can't muster even that level of enthusiasm or courtesy
towards
Your "if X then Y" logic is somewhat cockeyed -- Y is true independent
of X. Looking just at X: read some of my posts. You may find some with
a reasonable level of enthusiam and courtesy, especially where the
enquirer appears to have helped themselves to a reasonable extent
first and/or are having ESL difficulties and/or have not had a
response after 12 hours or more ...
John, you are an industrious and courteous helper on this list, no doubt
about it. I didn't mean to start a long debate about all this, I merely
wanted to point out that since noobs *will* often post without trying to
solve their own problem it's best to just ignore them if you don't feel
like answering.

If nobody takes pity on the questioner it will eventually be obvious
that some further access to one's own resources is necessary.

regards
Steve
 
T

Thorsten Kampe

* Chuck Connors (Fri, 21 Nov 2008 08:10:09 -0800 (PST))
Wow! What a change in direction from the previous post. Thank you
both for the help and the explanations. This will work great!

No, it will not. For manipulating CSV data in Python you use the
(*tada*) CSV module ("import csv"). The Python doc tells you how to use
it. Even being a PHP programmer doesn't excuse asking stupid questions.

Thorsten
 
C

Chuck Connors

Firstly, I would like to thank those that offered help. I was able to
get my data into the database and also have connectivity with the
mysql and can pull the data in/out at will. Hooray and thanks again.

Secondly, perhaps I overstated my abilities. I have written a couple
of websites from scratch that pull data in/out of databases and have
formatted their outputs for user consumption. I am by no means a php
expert and have never had occasion to use regular expressions for the
type of data I've been manipulating. My sarcastic reply was only in
response to the 'go google it' answer I received to what I thought was
a fair question. It's usually easiest to google something if you know
what you are looking for. At no point did I expect anyone to spend a
great deal of time working out my specific problem but I am most
grateful for those who did provide more than what could have been
expected.
 
R

r0g

John said:
Any help, pseudo code, or whatever push in the right direction would
be most appreciated. I am a novice Python programmer but I do have a
good bit of PHP programming experience.
<snip>

John said:
If I had to write such a script in Python, I'd be using the re and csv
modules in similar fashion to responses already posted. If I had to
write it in PHP, it'd be my first PHP script, so let's go Googling:
google("php regex") first hit:
http://www.regular-expressions.info/php.html
[yuk, 3 different toolkits; 3rd is PCRE, let's try that]
google("php csv") 3rd hit points to:
http://www.php.net/manual/en/function.fputcsv.php
Doesn't seem too difficult to me.
I'm sure it doesn't, it doesn't to me either, but only because we
already know what he needs! Do you think if the OP knew all about
regular expressions and understood that python has a handy csv module
that he'd be asking this question here?

(1) csv: The OP already knows what "csv" means -- see the subject
<snip content="blah blah blah">

As I and others have said a more appropriate response is no response.

Not everyone is aspiring to become a python guru. Some people have
things to do, timescales to work to and aren't professional programmers.

If I can spare someone a whole afternoon of slogging through manuals by
spending two minutes of my time answering them then I see no reason not
to, even if it spares them the 'rite of passage' learning you seem to
think they must endure.

What you experts deem so easy it's rude to ask about is a subjective
thing. I personally see a world of difference between the oldschool "Me
wan make game! Show me how make 3D game C++" posts you might see on
usenet and this guys polite detailed request for pointers.

Anyway shouting someone down for causing what you see as noise in your
forums is just increasing the noise for yourself and everyone else. Not
only that it clogs up the many web archives of this forum making people
who do google for answers to these 'easy' topics that little bit more
likely to run into your RTFM rant than the answer i.e. a bit less likely
to find the thing they're looking for and therefore more likely to come
to places like this to ask their 'trivial' questions and annoy you.

Roger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top