473,586 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SetField Content ("SY012M1", "art-nr", l[0])
PlayIt.PlayCont ent ("{CSB SY012M1|art-nr}{Enter}")
PlayIt.SetField Content ("SY012ADM1" , "001bez", l[1])
PlayIt.SetField Content ("SY012ADM1" , "005agr", l[2])
PlayIt.SetField Content ("SY012ADM1" , "006agr", l[3])
PlayIt.SetField Content ("SY012ADM1" , "009kst", l[4])
PlayIt.SetField Content ("SY012EHM1" , "005laeh", l[5])
PlayIt.SetField Content ("SY012EHM1" , "006lauf", l[6])
PlayIt.SetField Content ("SY012EHM1" , "011vkuf", l[7])
PlayIt.SetField Content ("SY012SDM1" , "012fest", l[8])
PlayIt.SetField Content ("SY012PRM1" , "001tpr", l[9])
PlayIt.SetField Content ("SY012PRM1" , "002wpr", l[10])
PlayIt.SetField Content ("SY012PRM1" , "003plpr", l[11])
PlayIt.PlayCont ent ("{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 1514
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********@yaho o.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.SetField Content ("SY012M1", "art-nr", l[0])
PlayIt.PlayCont ent ("{CSB SY012M1|art-nr}{Enter}")
PlayIt.SetField Content ("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********@yah oo.com> schrieb im Newsbeitrag
news:23******** *************** ***@posting.goo gle.com...
| 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.SetField Content ("SY012M1", "art-nr", l[0])
| PlayIt.PlayCont ent ("{CSB SY012M1|art-nr}{Enter}")
| PlayIt.SetField Content ("SY012ADM1" , "001bez", l[1])
| PlayIt.SetField Content ("SY012ADM1" , "005agr", l[2])
| PlayIt.SetField Content ("SY012ADM1" , "006agr", l[3])
| PlayIt.SetField Content ("SY012ADM1" , "009kst", l[4])
| PlayIt.SetField Content ("SY012EHM1" , "005laeh", l[5])
| PlayIt.SetField Content ("SY012EHM1" , "006lauf", l[6])
| PlayIt.SetField Content ("SY012EHM1" , "011vkuf", l[7])
| PlayIt.SetField Content ("SY012SDM1" , "012fest", l[8])
| PlayIt.SetField Content ("SY012PRM1" , "001tpr", l[9])
| PlayIt.SetField Content ("SY012PRM1" , "002wpr", l[10])
| PlayIt.SetField Content ("SY012PRM1" , "003plpr", l[11])
| PlayIt.PlayCont ent ("{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*****@visual trans.de> schrieb im Newsbeitrag
news:bt******** **@news4.tilbu1 .nb.home.nl...
| "Boomer" <bo********@yah oo.com> schrieb im Newsbeitrag
| news:23******** *************** ***@posting.goo gle.com...
| | 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.SetField Content ("SY012M1", "art-nr", l[0])
| | PlayIt.PlayCont ent ("{CSB SY012M1|art-nr}{Enter}")
| | PlayIt.SetField Content ("SY012ADM1" , "001bez", l[1])
| | PlayIt.SetField Content ("SY012ADM1" , "005agr", l[2])
| | PlayIt.SetField Content ("SY012ADM1" , "006agr", l[3])
| | PlayIt.SetField Content ("SY012ADM1" , "009kst", l[4])
| | PlayIt.SetField Content ("SY012EHM1" , "005laeh", l[5])
| | PlayIt.SetField Content ("SY012EHM1" , "006lauf", l[6])
| | PlayIt.SetField Content ("SY012EHM1" , "011vkuf", l[7])
| | PlayIt.SetField Content ("SY012SDM1" , "012fest", l[8])
| | PlayIt.SetField Content ("SY012PRM1" , "001tpr", l[9])
| | PlayIt.SetField Content ("SY012PRM1" , "002wpr", l[10])
| | PlayIt.SetField Content ("SY012PRM1" , "003plpr", l[11])
| | PlayIt.PlayCont ent ("{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
2372
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 some cases there is a further complication: module importing through an indirect mechanism, like: exec "from " + xxx + " import *". A part the fact...
4
2657
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 piece which holds the programs reference: globals, functions, classes, modules etc. The objects of this file (functions and classes) are directly...
11
3391
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 the last field, it only checks the top few 'cells' to see if there is any data, if not, the field is not imported). How do I 'force' Access to...
7
3295
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 buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY...
3
1794
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 module, oddmodule.py (below), that defines a variable, OddVariable, by assigning a value A to it. The file I execute, mainfile.py, imports and re-binds...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.