0

Whenever I type this variable and didn't even use it

text = " أقام المدعي دعواه ضد المدعى عليه طالبا إلزامه بتسليمه باقي ثمن جزء من قطعتي أرض باعها عليه قبل ثمانية وعشرين عاما وقام بإفراغهما له آنذاك، وبعرض الدعوى على المدعى عليه أقر بالبيع ودفع بأنه سلم للمدعي كامل الثمن، وبطلب البينة من المدعي أبرز سندا خطيا يتضمن إقرار المدعى عليه بالمبلغ المدعى به، وبعرضه عليه قرر أنه كتبه قبل إفراغ الأرضين وأنه سلم المدعي باقي الثمن عند الإفراغ، ونظراً لأن المدعي لم يذكر مانعاً شرعياً من المطالبة بحقه، ولأن سكوت صاحب الحق عن المطالبة بحقه مدة طويلة من الزمن مع قدرته على ذلك وعدم وجود مانع شرعي يمنعه من المطالبة دليل على تركه لهذا الحق وإمارة على عدم أحقيته به، ولأن أن القول المختار في مدة التقادم أنه راجع لاجتهاد القاضي، ولأن مدة سكوت المدعي عن إقامة الدعوى تعد طويلة جداً، لذا فقد حكم القاضي برد الدعوى، فاعترض المدعي، وصدق الحكم من محكمة الاستئناف ."

it gives me this error

SyntaxError: Non-UTF-8 code starting with '\xd8' in file "file path" on line 15, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

I'm trying to check if the word exists in the string i searched a lot but can't figure it out Can you help me? thanks

tripleee
  • 175,061
  • 34
  • 275
  • 318
Hosam Gamal
  • 163
  • 1
  • 2
  • 12
  • 2
    Your source code (the .py file) has to be saved as utf-8. Depending on which editor you use, it may be saved in a different encoding and Python will then complain. – zvone Oct 18 '20 at 15:03
  • 1
    We can’t tell you the correct encoding without seeing (a representative, ideally small sample of) the actual bytes of the code in an unambiguous representation; a hex dump of the problematic byte(s) with a few bytes of context on each side is often enough, especially if you can tell us what you think those bytes are supposed to represent. See also https://meta.stackoverflow.com/questions/379403/problematic-questions-about-decoding-errors – tripleee Oct 18 '20 at 15:09
  • thank you very much I'm using Pycharm and I made sure that the file is saved in utf-8 – Hosam Gamal Oct 18 '20 at 16:21
  • add `# -*- coding: utf-8 -*-` at the beginning of your file – Yomna Mansour Nov 18 '21 at 16:13

1 Answers1

-1

I tried the same variable you attached and it works fine, if you can provide more code I may be able to help you better

If you want to check if a word is in a block of text you can use the Python keyword in

like so

text = " أقام المدعي دعواه ضد المدعى عليه طالبا إلزامه بتسليمه باقي ثمن جزء من قطعتي أرض باعها عليه قبل ثمانية وعشرين عاما وقام بإفراغهما له آنذاك، وبعرض الدعوى على المدعى عليه أقر بالبيع ودفع بأنه سلم للمدعي كامل الثمن، وبطلب البينة من المدعي أبرز سندا خطيا يتضمن إقرار المدعى عليه بالمبلغ المدعى به، وبعرضه عليه قرر أنه كتبه قبل إفراغ الأرضين وأنه سلم المدعي باقي الثمن عند الإفراغ، ونظراً لأن المدعي لم يذكر مانعاً شرعياً من المطالبة بحقه، ولأن سكوت صاحب الحق عن المطالبة بحقه مدة طويلة من الزمن مع قدرته على ذلك وعدم وجود مانع شرعي يمنعه من المطالبة دليل على تركه لهذا الحق وإمارة على عدم أحقيته به، ولأن أن القول المختار في مدة التقادم أنه راجع لاجتهاد القاضي، ولأن مدة سكوت المدعي عن إقامة الدعوى تعد طويلة جداً، لذا فقد حكم القاضي برد الدعوى، فاعترض المدعي، وصدق الحكم من محكمة الاستئناف ."

print("محكمة" in text) # -> True

This will give true because محكمة is in the text

You can then use if statements like so

if "محكمة" in text:
  print("It's in the text")
else:
  print("This text doesn't have the word.")
Dharman
  • 30,962
  • 25
  • 85
  • 135
Abod
  • 58
  • 1
  • 7
  • The title is clearly misleading; the OP's code is probably actually fine, but they are basically asking us to guess which encoding they are using. – tripleee Oct 18 '20 at 15:19
  • thank you, my friend but the answer was to make a #coding=utf-8 on the top of the page and it worked – Hosam Gamal Oct 18 '20 at 16:27
  • I read this part "I'm trying to check if the word exists in the string i searched a lot but can't figure it out Can you help me? thanks" from the question and tried to answer it – Abod Oct 22 '20 at 11:47