[Tutor] unable to use find(), index()

2011-12-08 Thread surya k

I am using the following code 
astr = foobarstr1 =fooastr.find(str1, beg=0, end=3)

This is showing the following error
Traceback (most recent call last):  File interactive input, line 1, in 
moduleTypeError: find() takes no keyword arguments
I even tried by importing string module, but it isn't working.
This same problem with find()
Could you please help me!

  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unable to use find(), index()

2011-12-08 Thread Walter Prins
Hi Surya,

On 8 December 2011 11:19, surya k sur...@live.com wrote:

 astr.find(str1, beg=0, end=3)
 This is showing the following error
 Traceback (most recent call last):  File interactive input, line 1, in
 moduleTypeError: find() takes no keyword arguments


See the documentation for the str.find() method here:
http://docs.python.org/release/2.5.2/lib/string-methods.html

The error says that find() does not take any keyword arguments, and you've
supplied 2, (namely, beg and end.) So, try calling find() without
trying to specify beg and end as keyword (e.g. named as you've done)
arguments.

Also read up on keyword arguments (and arguments in general):
http://docs.python.org/release/1.5.1p1/tut/keywordArgs.html

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unable to use find(), index()

2011-12-08 Thread Christian Witts

On 2011/12/08 01:19 PM, surya k wrote:
I am using the following code 
astr = foobarstr1 =fooastr.find(str1, beg=0, end=3)


This is showing the following error
Traceback (most recent call last):  File interactive input, line 1, 
inmoduleTypeError: find() takes no keyword arguments
I even tried by importing string module, but it isn't working.
This same problem with find()
Could you please help me!


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Your traceback message gives you the reason it's not working, `find() 
takes no keyword arguments`. The function only takes positional 
arguments so if you just write `astr.find(str1, 0, 3)` it will work as 
you expect it to.


 help(''.find)
Help on built-in function find:

find(...)
S.find(sub [,start [,end]]) - int

Return the lowest index in S where substring sub is found,
such that sub is contained within s[start:end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.

--

Christian Witts
Python Developer
//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unable to use find(), index()

2011-12-08 Thread Steven D'Aprano

surya k wrote:
I am using the following code 
astr = foobarstr1 =fooastr.find(str1, beg=0, end=3)


You have mangled the code in your email and lost line breaks. Fortunately this 
is simple enough to fix:


astr = foobar
str1 =foo
astr.find(str1, beg=0, end=3)

Please take more care to post code in PLAIN TEXT, not html rich text, which 
may mangle line breaks and break the code.



This is showing the following error
Traceback (most recent call last):  File interactive input, line 1, in 
moduleTypeError: find() takes no keyword arguments
I even tried by importing string module, but it isn't working.
This same problem with find()
Could you please help me!


Did you read the error message?

find() takes no keyword arguments

This means just what it says: the find method does not take keyword arguments. 
Do you understand what keyword arguments are?



# Wrong, will not work:
astr.find(str1, begin=23, end=42)

# Right, will work:
astr.find(str1, 23, 42)


--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor