importing

Discussion in 'Python' started by Boomer, Jan 3, 2004.

  1. Boomer

    Boomer Guest

    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!!!
    Boomer, Jan 3, 2004
    #1
    1. Advertising

  2. 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
    Mark McEahern, Jan 3, 2004
    #2
    1. Advertising

  3. Boomer

    Gerrit Holl Guest

    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/
    Gerrit Holl, Jan 3, 2004
    #3
  4. Boomer

    Guest

    On 3 Jan 2004 12:49:56 -0800, (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
    , Jan 3, 2004
    #4
  5. "Boomer" <> schrieb im Newsbeitrag
    news:...
    | 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!!!
    vincent wehren, Jan 4, 2004
    #5
  6. "vincent wehren" <> schrieb im Newsbeitrag
    news:bt9a52$nug$1.nb.home.nl...
    | "Boomer" <> schrieb im Newsbeitrag
    | news:...
    | | 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!!!
    |
    |
    vincent wehren, Jan 4, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Awah Teh

    Hyper-efficient Text Importing

    Awah Teh, Sep 2, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,159
    William Tasso
    Sep 3, 2003
  2. Marcus Schaemann
    Replies:
    1
    Views:
    1,071
    Eyck Jentzsch
    Sep 17, 2003
  3. Matt Breedlove
    Replies:
    1
    Views:
    424
    Eduard W. Lohmann
    Nov 24, 2003
  4. Lakshmi

    importing Aspx page into ASP page

    Lakshmi, Jul 2, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    372
    Kevin Spencer
    Jul 2, 2003
  5. plb
    Replies:
    2
    Views:
    349
Loading...

Share This Page