Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > importing

Reply
Thread Tools

importing

 
 
Boomer
Guest
Posts: n/a
 
      01-03-2004
Hi all,
I'm new to python which explains my problems with this. I'm trying
to import a .csv file(from excel) into some fields on my company's
software system(which interfaces to an sql database. Each row in this
..csv file needs to be split into smaller strings and each respective
string applied to it's field in the software then it's saved and the
next row starts, here's the code I've come up with so far.

f=open ("book1.csv", "r")
s=f.readline ()
while s != "":
print s
l = s.split(s,",",(11))
PlayIt.SetFieldContent ("SY012M1", "art-nr", l[0])
PlayIt.PlayContent ("{CSB SY012M1|art-nr}{Enter}")
PlayIt.SetFieldContent ("SY012ADM1", "001bez", l[1])
PlayIt.SetFieldContent ("SY012ADM1", "005agr", l[2])
PlayIt.SetFieldContent ("SY012ADM1", "006agr", l[3])
PlayIt.SetFieldContent ("SY012ADM1", "009kst", l[4])
PlayIt.SetFieldContent ("SY012EHM1", "005laeh", l[5])
PlayIt.SetFieldContent ("SY012EHM1", "006lauf", l[6])
PlayIt.SetFieldContent ("SY012EHM1", "011vkuf", l[7])
PlayIt.SetFieldContent ("SY012SDM1", "012fest", l[8])
PlayIt.SetFieldContent ("SY012PRM1", "001tpr", l[9])
PlayIt.SetFieldContent ("SY012PRM1", "002wpr", l[10])
PlayIt.SetFieldContent ("SY012PRM1", "003plpr", l[11])
PlayIt.PlayContent ("{CSB SY012M1|art-nr}{F2}")
s=f.readline ()
f.close ()

here's the error

Traceback (innermost last):
File "<string>", line 5, in ?
AttributeError: 'string' object has no attribute 'split'

the furthest I get is when I remove the s.split all together then I
can actually watch it import the first field correctly and switch
focus to the second field where it prints a comma and then hangs and
eventually gives the
argument 3: expected string list found
Someone told me I need to import the string module using "import
string" somewhere in my code, but when I do this I get an error
stating that no such module exists. I run this as script inside a
macro from another program and I believe the version of python this
program uses is 2.2.1.

Does anyone have any ideas? Any help would be wonderful!!!
 
Reply With Quote
 
 
 
 
Mark McEahern
Guest
Posts: n/a
 
      01-03-2004
On Sat, 2004-01-03 at 14:49, Boomer wrote:
> here's the error
>
> Traceback (innermost last):
> File "<string>", line 5, in ?
> AttributeError: 'string' object has no attribute 'split'


Try this from that program:

import sys
print sys.version

What does it say?

// m


 
Reply With Quote
 
 
 
 
Gerrit Holl
Guest
Posts: n/a
 
      01-03-2004
Boomer wrote:
> here's the error
>
> Traceback (innermost last):
> File "<string>", line 5, in ?
> AttributeError: 'string' object has no attribute 'split'


You are probably running an ancient Python version. Try upgrading to
Python 2.3. If you can't, try to import string and use string.split.
If this doesn't work, please send the error message to the list...

yours,
Gerrit.

--
15. If any one take a male or female slave of the court, or a male or
female slave of a freed man, outside the city gates, he shall be put to
death.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

 
Reply With Quote
 
engsolnom@ipns.com
Guest
Posts: n/a
 
      01-03-2004
On 3 Jan 2004 12:49:56 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (Boomer) wrote:

>Hi all,
> I'm new to python which explains my problems with this. I'm trying
>to import a .csv file(from excel) into some fields on my company's
>software system(which interfaces to an sql database. Each row in this
>.csv file needs to be split into smaller strings and each respective
>string applied to it's field in the software then it's saved and the
>next row starts, here's the code I've come up with so far.
>
>f=open ("book1.csv", "r")
>s=f.readline ()
>while s != "":
> print s
> l = s.split(s,",",(11))
> PlayIt.SetFieldContent ("SY012M1", "art-nr", l[0])
> PlayIt.PlayContent ("{CSB SY012M1|art-nr}{Enter}")
> PlayIt.SetFieldContent ("SY012ADM1", "001bez", l[1])


I'm just a newbie, but I'll take a crack at it any way...

split returns a list, and takes either one or two args. If the the first arg is missing, it defaults
to setting the separator to while space. In your case, you might try:

l = s.split(',', 11)

Norm
 
Reply With Quote
 
vincent wehren
Guest
Posts: n/a
 
      01-04-2004
"Boomer" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) om...
| Hi all,
| I'm new to python which explains my problems with this. I'm trying
| to import a .csv file(from excel) into some fields on my company's
| software system(which interfaces to an sql database. Each row in this
| .csv file needs to be split into smaller strings and each respective
| string applied to it's field in the software then it's saved and the
| next row starts, here's the code I've come up with so far.
|
| f=open ("book1.csv", "r")
| s=f.readline ()
| while s != "":
| print s
| l = s.split(s,",",(11))
| PlayIt.SetFieldContent ("SY012M1", "art-nr", l[0])
| PlayIt.PlayContent ("{CSB SY012M1|art-nr}{Enter}")
| PlayIt.SetFieldContent ("SY012ADM1", "001bez", l[1])
| PlayIt.SetFieldContent ("SY012ADM1", "005agr", l[2])
| PlayIt.SetFieldContent ("SY012ADM1", "006agr", l[3])
| PlayIt.SetFieldContent ("SY012ADM1", "009kst", l[4])
| PlayIt.SetFieldContent ("SY012EHM1", "005laeh", l[5])
| PlayIt.SetFieldContent ("SY012EHM1", "006lauf", l[6])
| PlayIt.SetFieldContent ("SY012EHM1", "011vkuf", l[7])
| PlayIt.SetFieldContent ("SY012SDM1", "012fest", l[8])
| PlayIt.SetFieldContent ("SY012PRM1", "001tpr", l[9])
| PlayIt.SetFieldContent ("SY012PRM1", "002wpr", l[10])
| PlayIt.SetFieldContent ("SY012PRM1", "003plpr", l[11])
| PlayIt.PlayContent ("{CSB SY012M1|art-nr}{F2}")
| s=f.readline ()
| f.close ()
|
| here's the error
|
| Traceback (innermost last):
| File "<string>", line 5, in ?
| AttributeError: 'string' object has no attribute 'split'
|
| the furthest I get is when I remove the s.split all together then I
| can actually watch it import the first field correctly and switch
| focus to the second field where it prints a comma and then hangs and
| eventually gives the
| argument 3: expected string list found
| Someone told me I need to import the string module using "import
| string" somewhere in my code, but when I do this I get an error
| stating that no such module exists. I run this as script inside a
| macro from another program and I believe the version of python this
| program uses is 2.2.1.

Hi "Boomer"

if you are using version V3.91 or lower of your companies software, the
embedded Python will still be at 1.52. If it is V4.20 it'll be Python 2.2.2.
Since I know that the Python standard library is not shipped with the
software you are referring to, you need to either install Python (in the
version corresponding to your version) on your local machine, or an
accessible share and set your environment properly.

Looking at your example I am pretty confident that your are using V391 which
embedds 1.52. As a quick fix: check if either "string.pyc" or "string.py"
lives in your w32 directory or - if you are executing via a .pli file - in
the directory "playit.exe" lives in. If that is not the case, get either
module in the correct version and copy it to the directories just described.
This will fix your problem (until you try to import another module
ofcourse).

HTH

Vincent Wehren















|
| Does anyone have any ideas? Any help would be wonderful!!!


 
Reply With Quote
 
vincent wehren
Guest
Posts: n/a
 
      01-04-2004

"vincent wehren" <(E-Mail Removed)> schrieb im Newsbeitrag
news:bt9a52$nug$(E-Mail Removed)1.nb.home.nl...
| "Boomer" <(E-Mail Removed)> schrieb im Newsbeitrag
| news:(E-Mail Removed) om...
| | Hi all,
| | I'm new to python which explains my problems with this. I'm trying
| | to import a .csv file(from excel) into some fields on my company's
| | software system(which interfaces to an sql database. Each row in this
| | .csv file needs to be split into smaller strings and each respective
| | string applied to it's field in the software then it's saved and the
| | next row starts, here's the code I've come up with so far.
| |
| | f=open ("book1.csv", "r")
| | s=f.readline ()
| | while s != "":
| | print s
| | l = s.split(s,",",(11))
| | PlayIt.SetFieldContent ("SY012M1", "art-nr", l[0])
| | PlayIt.PlayContent ("{CSB SY012M1|art-nr}{Enter}")
| | PlayIt.SetFieldContent ("SY012ADM1", "001bez", l[1])
| | PlayIt.SetFieldContent ("SY012ADM1", "005agr", l[2])
| | PlayIt.SetFieldContent ("SY012ADM1", "006agr", l[3])
| | PlayIt.SetFieldContent ("SY012ADM1", "009kst", l[4])
| | PlayIt.SetFieldContent ("SY012EHM1", "005laeh", l[5])
| | PlayIt.SetFieldContent ("SY012EHM1", "006lauf", l[6])
| | PlayIt.SetFieldContent ("SY012EHM1", "011vkuf", l[7])
| | PlayIt.SetFieldContent ("SY012SDM1", "012fest", l[8])
| | PlayIt.SetFieldContent ("SY012PRM1", "001tpr", l[9])
| | PlayIt.SetFieldContent ("SY012PRM1", "002wpr", l[10])
| | PlayIt.SetFieldContent ("SY012PRM1", "003plpr", l[11])
| | PlayIt.PlayContent ("{CSB SY012M1|art-nr}{F2}")
| | s=f.readline ()
| | f.close ()
| |
| | here's the error
| |
| | Traceback (innermost last):
| | File "<string>", line 5, in ?
| | AttributeError: 'string' object has no attribute 'split'
| |
| | the furthest I get is when I remove the s.split all together then I
| | can actually watch it import the first field correctly and switch
| | focus to the second field where it prints a comma and then hangs and
| | eventually gives the
| | argument 3: expected string list found
| | Someone told me I need to import the string module using "import
| | string" somewhere in my code, but when I do this I get an error
| | stating that no such module exists. I run this as script inside a
| | macro from another program and I believe the version of python this
| | program uses is 2.2.1.
|
| Hi "Boomer"
|
| if you are using version V3.91 or lower of your companies software, the
| embedded Python will still be at 1.52. If it is V4.20 it'll be Python
2.2.2.
| Since I know that the Python standard library is not shipped with the
| software you are referring to, you need to either install Python (in the
| version corresponding to your version) on your local machine, or an
| accessible share and set your environment properly.
|
| Looking at your example I am pretty confident that your are using V391
which
| embedds 1.52. As a quick fix: check if either "string.pyc" or "string.py"
| lives in your w32 directory or - if you are executing via

Just for the record, I mean the w32 directory of the ERP system you are
referring to!

Vincent Wehren




a .pli file - in
| the directory "playit.exe" lives in. If that is not the case, get either
| module in the correct version and copy it to the directories just
described.
| This will fix your problem (until you try to import another module
| ofcourse).
|
| HTH
|
| Vincent Wehren
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
| | Does anyone have any ideas? Any help would be wonderful!!!
|
|


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM
Importing Outlook Mail folders and Contacts? William W. Plummer Firefox 1 07-02-2004 04:25 PM
ThunderBird- importing email from Pegasus _ Firefox 1 06-22-2004 04:33 PM
Importing mail messages from a directory of Mozilla 1.4 to 1.5 mrzac Firefox 2 12-23-2003 05:45 PM
Still need help importing address book Axl Firefox 2 12-16-2003 09:45 AM



Advertisments