473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

importing

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!!!
Jul 18 '05 #1
5 1509
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
Jul 18 '05 #2
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/

Jul 18 '05 #3
On 3 Jan 2004 12:49:56 -0800, bo********@yahoo.com (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
Jul 18 '05 #4
"Boomer" <bo********@yahoo.com> schrieb im Newsbeitrag
news:23**************************@posting.google.c 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!!!
Jul 18 '05 #5

"vincent wehren" <vi*****@visualtrans.de> schrieb im Newsbeitrag
news:bt**********@news4.tilbu1.nb.home.nl...
| "Boomer" <bo********@yahoo.com> schrieb im Newsbeitrag
| news:23**************************@posting.google.c 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!!!
|
|
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In...
4
by: jean-marc | last post by:
As an application programmer, I'm not well versed in the material aspects of computing (memory, cpu, bus and all). My understanding of imports in Python is such: the __main__ program is the center...
11
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
3
by: rs387 | last post by:
Hi, I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. In summary, here's what happens. I have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.