0

Right now this is my code:

test_score = 500
print(important_aspect)
print()
important_aspect = '"%s"' %important_aspect
print(important_aspect)

if important_aspect == "\x7fVrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' \x7fUitdaging: Ik wil mij competitief en effectief voelen.', ' \x7fVerbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk.":
    test_score = test_score + 100

print (test_score)

The output is the following:

\x7fVrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' \x7fUitdaging: Ik wil mij competitief en effectief voelen.', ' \x7fVerbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk.

"\x7fVrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' \x7fUitdaging: Ik wil mij competitief en effectief voelen.', ' \x7fVerbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk."
500

How can I make sure the python reads the important_aspect data equal as the data in the if-statement, so the output will be 600? The data from the important_aspect variable comes from a cel in an excel file saved as csv.

1
  • The code you've shown for the value of important_aspect is not valid Python, so it's hard to tell exactly what the desired behavior is here. Please edit your post to include a minimal reproducible example. Commented Jun 3, 2020 at 13:21

2 Answers 2

2

This is because you missed the quotes for the string important_aspect, check this:

important_aspect = "\x7fVrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' \x7fUitdaging: Ik wil mij competitief en effectief voelen.', ' \x7fVerbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk."

Updated version for edited question:

You can use string literals for comparing with raw string r

test_score = 500

string_for_compare = r"\x7fVrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' \x7fUitdaging: Ik wil mij competitief en effectief voelen.', ' \x7fVerbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk."

if important_aspect == string_for_compare:
    test_score = test_score + 100

print(test_score)
# 600

This is because escape characters, if you print string for comparing without r for example you get:

Vrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' Uitdaging: Ik wil mij competitief en effectief voelen.', ' Verbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk.
Sign up to request clarification or add additional context in comments.

3 Comments

@Diew, no problem, please mark the right answer with the solved status
I have a new problem now, its not working yet. I changed it in the question. Do you understand why its not working?
@Diew, sure, can you check updated version, you can use string literal
0

Cannot reproduce:

test_score = 500

important_aspect = r"\x7fVrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' \x7fUitdaging: Ik wil mij competitief en effectief voelen.', ' \x7fVerbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk."

if important_aspect == r"\x7fVrijheid: Ik wil mijn eigen acties en keuzes maken. Ik wil autonomie hebben.', ' \x7fUitdaging: Ik wil mij competitief en effectief voelen.', ' \x7fVerbinden: Ik wil mij verbinden met anderen. Multiplayer games zijn daarom belangrijk.":
    test_score = test_score + 100

print (test_score)
# 600

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.