importing

B

Boomer

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!!!
 
M

Mark McEahern

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
 
G

Gerrit Holl

Boomer said:
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.
 
E

engsolnom

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
 
V

vincent wehren

| 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!!!
 
V

vincent wehren

| | | 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!!!
|
|
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top