I
I
in10ogram2018-09-05 00:17:17
Python
in10ogram, 2018-09-05 00:17:17

Why does the "invalid character in identifier" error occur?

Please help me, I've been scratching my head for an hour
Code

import telebot

import constans

bot = telebot.TeleBot(constans.token)

#upd = bot.get_updates()
#print (upd)
#last_upd = upd[-1]
#message_from_user = last_upd.message
#print(message_from_user)

print(bot.get_me())

def log(message: object, answer: object) -> object:
    print("/n ------")
    from datetime import datetime
    print(datetime.now())
    print("Сообщение от {0} {1}. (id = {2}) \n Текст = {3}".format(message.from_user.first_name, message.from_user.last_name, str(message.from_user.id), message.text))


@bot.message_handler(commands=['help'])
def handle_text(message):
    answer = "Мои возможности ограничены. Sorry!"
    log(message, answer)
    bot.send_message(message.chat.id, answer )

@bot.message_handler(commands=['start'])
def handle_text(message):
    answer = "Hello! You are welcome!"
    log(message, answer)
    bot.send_message(message.chat.id, answer)

@bot.message_handler(commands=['settings'])
def handle_text(message):
    answer = "Тут пусто)"
    log(message, answer)
    bot.send_message(message.chat.id,answer )


@bot.message_handler(content_types=['text'])
def handle_text(message):
    answer = "USUS"
    if message.text == "a":
        answer = "b"
        log(message, answer)
        bot.send_message(message.chat.id, answer)
    elif message.text == "c":
        answer = "d"
        log(message, answer)
        bot.send_message(message.chat.id,answer)
    else:
        log(message, answer)
        bot.send_message(message.chat.id, answer)
        
bot.polling(none_stop=True, interval=0)

Mistake
C:\Users\lucky\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/lucky/PycharmProjects/untitled/Telegram.py
  File "C:/Users/lucky/PycharmProjects/untitled/Telegram.py", line 55
    bot.polling(none_stop=True, interval=0)
                                           ^
SyntaxError: invalid character in identifier

Process finished with exit code 1

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eugene, 2018-09-05
@immaculate

You get a perfectly clear message: you have some strange non-printable Unicode character behind the last closing bracket.

I
index0h, 2015-03-10
@phpus

1. Just php files:
+ Yes, it’s easy to work with them
- In the case when there are really a lot of translations, you will pour them out from memory
- Edits must be made by the proger
2. PO -> MO files:
+ There are a lot of tools to work with them
+ Works with php pretty quickly and doesn't eat much memory
- Mandatory regeneration MO
- If translations are done by a third person, merging is not the most pleasant experience
3. DB:
+ process
- Increased requirements for migrations
- Mandatory partitioning and caching
Z.Y. I do NOT recommend making the original language for translations native. It's better to use specific style lines: '{moduleName}:{controllerName}:{actionName}:{blockName}:phrase'. Otherwise, there is a possibility of merging translations and a situation may arise:
In the delete block, the text "OK" was replaced with "Delete", and in a magically incomprehensible way, a key of the same name will appear on the registration page under the input form.

E
Evgeny Elchev, 2015-03-09
@rsi

Growing out of frameworks is really weird to hear, but it's up to you. It's strange then why you ask such questions.
donem.com/en/new?id1
is your route's "en" language id. Define a repository for translations. It could be a base, it could be files. Oddly enough, WP has an excellent implementation in this regard, they store translations in .po files, which even such moments as 1 elephant (elephant), 2 elephants (elephants), 5 elephants (elephants) are taken into account. Write one class that, based on the language identifier and the original word, will output the translation. Does your CMS have a life cycle, templates? Here, call this translation class at the time of template compilation. And it will look something like this - t("elephant"), and there inside there is already a match between the source string and the translation.
If you want to translate not only the interface, but also the content (for example, articles), then define a structure in the database (do you store materials in the database?) That would allow you to store the same data in different languages ​​and let your translation class give templates data in desired language based on the language ID.

I
Ilya Bobkov, 2015-03-09
@heksen

Something like this.

/*
----------------------
 МУЛЬТИЯЗЫЧНОСТЬ
----------------------
*/
if ( $_GET["func"] == "GetString" )
{	
  if ( isset($_GET["lang"]) && isset($_GET["string"]) )
  {
     $array = parse_ini_file( $_GET["lang"].".ini" );
     echo $array[ $_GET["string"] ];
  }
  else echo "параметры отсутсвуют!";
}
?>

language strings are in the ini file in the format:
string = value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question