-1

I'm just wondering how I would fix this

app = first[0:8] and second[0:8]

That doesn't work but if I remove "and..." it does but I need both.

Edited by DEATHMASTER: n/a

4
Contributors
12
Replies
13
Views
7 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • [QUOTE]input was defined earlier in the code[/QUOTE] Dont ever do that. [CODE]>>> input = 'hi' >>> input 'hi' >>> dir(input) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', … Read More

-1

I'm just wondering how I would fix this

app = first[0:8] and second[0:8]

That doesn't work but if I remove "and..." it does but I need both.

can you do
f = first[0:8]
s = second[0:8]
apps = f+s or whatever comination you require it for

-1

I get the same thing with that (nothing).

Just to clear things up does second refer to the same text as first?

-1

Just to clear things up does second refer to the same text as first?

No it's a different string of text.

0

What are you trying to do?

>>> first = 'stringisfun'
>>> second = 'iamsecond'
>>> app = first[0:8]
>>> app
'stringis'
>>> app1 = second[0:8]
>>> app1
'iamsecon'
>>> app + app1
'stringisiamsecon'
>>>

"and or" are used for decision control(Boolean logic)
So if you want both first and second to run that will never work.

#both test conditions are true and it print
>>> a = 4
>>> if a > 3 and a < 10:
	print 'this work'
	
this work

#if one is false it will not print
>>> if a > 3 and a > 10:
	print 'this work'


#if we use "or" only one test conditions has to be true.
>>> if a > 3 or a > 10:
	print 'this work'

this work
-2

I see how that works, a little more specifically I'm trying to use it in this which isn't working

if input.find(app + app1) == 1:
    print "output"
-1

input is a method that is build in to python.
And you can not do this input.find

>>> input.find

Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    input.find
AttributeError: 'builtin_function_or_method' object has no attribute 'find'

>>> input('your number: ')
your number: 5
5

And comparing app,app1 to 1 is always false.

>>> app == 1
False
>>>

Edited by snippsat: n/a

-1

input was defined earlier in the code and another example of a how the "== 1" works in this same part of the 'if' statement:

elif input.find(diffstring) == 1:
            print "Ousted."

That part works, but simply making it input.find(diffstring + app) == 1
makes it not work, but I need to refer to those 2 strings without changing them.

1

input was defined earlier in the code

Dont ever do that.

>>> input = 'hi'
>>> input
'hi'
>>> dir(input)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>

Now input works as a string method.
And you can use input.find(),but this is very wrong.
Dont ever use build in python method as variables.

If you not sure use "my" before so my_input.

0
app = 'abc'
app1 = 'def'
my_input= 'xabcdefgh'

# find() returns the index at which app+app1 ('abcdef')
# appears in string my_input, this should print output
if my_input.find(app + app1) == 1:
    print "output"

Do not under any circumstances use 'input' as a variable name for your string! If you got the code from someone else, it is crap!

If you use 'input' as a variable name early on in your code, you cannot use the function input() later, because 'input' is now a key in the global dictionary and identifies a string object not a function.

0

Ok I did precisely that (but app = array) ^ with input renamed to my_input and it still doesn't give the print statement.

Also what's all these -1 on my posts in this thread?

Edited by DEATHMASTER: n/a

0

At this point you need to give us the whole code, otherwise we will talk about some nebulous thing for ever.

I am not sure what -1 you are talking about.

Note:
Okay, now I see all those -1 in front of every newer thread (not post).
I looked into it and found out that it is associated with the up and down arrows that are a new feature here, and are supposed to be some kind of a flaky rating system.

It looks like some clown from the C forum who hates Python went around and down clicked all the authors of newer threads! The new feature is rather childish to say the least, so I apologize. I have requested for it to be removed.

Edited by vegaseat: stupid rating system

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.