I've encountered an anomaly while using the string module (specifically,
string.split). Here's the snippet:
import string
address2 = ' '
line = 'function, dealer, type, firstname, lastname, vin, blank'
print 'Address2 Type (first check): ', type(address2)
function, dealer, type, firstname, lastname, vin, blank =
string.split(line, ',')
print 'Address2 type (second check): ', type(address2)
I've extracted this from a larger script, but the error happens roughly
the same way. Now, here's what I would expect to see:
Address2 Type (first check): <type 'str'>
Address2 type (second check): <type 'str'>
Here's what I get instead:
Address2 Type (first check): <type 'str'>
Address2 type (second check):
Traceback (most recent call last):
File
"C:\PROGRA~1\Python\lib\site-packages\Pythonwin\pywin\framework\scriptut
ils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Program Files\Python\test1.py", line 7, in ?
print 'Address2 type (second check): ', type(address2)
TypeError: 'str' object is not callable
What the heck is going on here? I figure I'm just missing something.
- Mark Daley
Product Manager
Diversiform, Inc.
1-800-444-3445 2 1209
mark wrote: address2 = ' ' line = 'function, dealer, type, firstname, lastname, vin, blank' print 'Address2 Type (first check): ', type(address2) function, dealer, type, firstname, lastname, vin, blank = # ^ LINE ABOVE CONTAINS ERROR string.split(line, ',') print 'Address2 type (second check): ', type(address2)
<snip> Address2 Type (first check): <type 'str'> Address2 type (second check): Traceback (most recent call last): File "C:\PROGRA~1\Python\lib\site-packages\Pythonwin\pywin\framework\scri ptut ils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Program Files\Python\test1.py", line 7, in ? print 'Address2 type (second check): ', type(address2) TypeError: 'str' object is not callable
In the marked line, you assign a string to a variable called
"type". This means that you overwrote your reference to the type
function that you are trying to use in type(address2). When you "call"
type(address2) you are now trying to call the string which you have
assigned to the name "type". Use a different name for your variable (a
name that the library doesn't use) and you will be fine.
--
--OKB (not okblacke)
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
> address2 = ' ' line = 'function, dealer, type, firstname, lastname, vin, blank' print 'Address2 Type (first check): ', type(address2) function, dealer, type, firstname, lastname, vin, blank =
^^^^^
Here you rebind the name type (which is initially bound to <type 'type'>,
that can be called with an argument to get its type) to the string ' '.
Hence the second
type(address2)
doesn't work.
You can do this on all symbols/names in python, which can cause confusing
errors.
Diez This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave Anderson |
last post by:
Consider the following:
var GUID = Server.CreateObject("Scriptlet.TypeLib").GUID
Let's assume GUID is {9A46FCC9-A7A1-4C96-9394-B1A966CEC081}.
I happened to notice that if I concatenate this...
|
by: Stan Milam |
last post by:
The following code implements a strcat-like function which can receive a
variable number of arguments. I thought it would be faster if I kept a
pointer to the end of the string as it is built so...
|
by: questions? |
last post by:
say I have a structure which have an array inside.
e.g.
struct random_struct{
char name;
int month;
}
if the array is not intialized by me, in a sense after I allocated a
|
by: kevin |
last post by:
Hello!
So I was reading O'Reilly's C++ in a Nutshell when I came accross
something interesting:
The class definition for basic_ostream contains numerous overloaded
operator<< functions:
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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: 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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |