Python Forum
i want to write symbole as varibales in python to make translator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i want to write symbole as varibales in python to make translator
#1
hey

i want to write symbole as varibales in python to make translator .
for example: i want this [-10;-30] became this (-10,-30).
i want my code translate automatically those symbols: [ ; ]


i tried to type this but i have error :

[='('
]=')'
;=','
Reply
#2
Could you provide more details about what it is you are trying to do?

Python has rules about identifier (variable, function, class, method) names, the most important being that they must be names. [ cannot be a variable name. 123 cannot be a variable name 'variable' cannot be a variable name. You can use upper and lower case letters, numbers and underscores. The first character must be a letter. Identifiers cannot be a python keyword (if, with, for, while, in …)
Reply
#3
(Feb-01-2021, 04:07 PM)deanhystad Wrote: Could you provide more details about what it is you are trying to do?

Python has rules about identifier (variable, function, class, method) names, the most important being that they must be names. [ cannot be a variable name. 123 cannot be a variable name 'variable' cannot be a variable name. You can use upper and lower case letters, numbers and underscores. The first character must be a letter. Identifiers cannot be a python keyword (if, with, for, while, in …)

i want to create a script who do this : when i type this [20;20] i want this result (20,20)
^^!
Reply
#4
Need more details. What do you mean "when I type this[20, 20] I want this result (20, 20)"? Where are you typing? Are you trying to make a tool that sits between you and the interpreter changing keystrokes as you type? Are you trying to make a file processor that will scan a file and change some of the content?

Your description may sound clear to you, but you have all the context and I have none. You need to provide the context.
Reply
#5
(Feb-01-2021, 06:26 PM)deanhystad Wrote: Need more details. What do you mean "when I type this[20, 20] I want this result (20, 20)"? Where are you typing? Are you trying to make a tool that sits between you and the interpreter changing keystrokes as you type? Are you trying to make a file processor that will scan a file and change some of the content?

Your description may sound clear to you, but you have all the context and I have none. You need to provide the context.

i'm sorry i will try to explain more .
i use a website who gives me the indications of a game quest . like this :[20, 20] . as you see in the picture marks yellow .
and me i want to copy this indication from the website to the game but without brakets [] . that is way i want to make a script by python , who will work as atranslator .
i want to copy the indicator from website to my python project to replace brakets by () and then copy the final result to the game .
[Image: Capture.png]
Reply
#6
Let's make sure I understand.

You have a game. It takes input. The input has to have a certain format. You cannot change the game to accept a different format.

You have a website that provides input for your game. The information from the website is not in the correct format for your game.

You want a translator that will take the output from the website and convert it to a format that can be input to the game.

Is that correct?

If that is correct, I would write a really small GUI application (using tkinter for example). There would be a control for pasting text from the website, a function that translates the text, and a control that displays the translated text so it could be copied and pasted into your game.
import tkinter as tk

translation = {'[':'(', ']':')', ';':','}

def translate(*args):
    outstr.set(''.join([translation.get(c, c) for c in inpstr.get()]))
    
root = tk.Tk()
inpstr = tk.StringVar()
outstr = tk.StringVar()

inpstr.trace('w', translate)

tk.Label(root, text='From Website:').pack(padx=5, pady=5)
tk.Entry(root, textvariable=inpstr, width=20).pack(padx=5, pady=5)

tk.Label(root, text='To Game:').pack(padx=5, pady=5)
tk.Entry(root, textvariable=outstr, width=20).pack(padx=5, pady=5)

tk.mainloop()
Reply
#7
(Feb-01-2021, 08:22 PM)deanhystad Wrote: Let's make sure I understand.

You have a game. It takes input. The input has to have a certain format. You cannot change the game to accept a different format.

You have a website that provides input for your game. The information from the website is not in the correct format for your game.

You want a translator that will take the output from the website and convert it to a format that can be input to the game.

Is that correct?

If that is correct, I would write a really small GUI application (using tkinter for example). There would be a control for pasting text from the website, a function that translates the text, and a control that displays the translated text so it could be copied and pasted into your game.
import tkinter as tk

translation = {'[':'(', ']':')', ';':','}

def translate(*args):
    outstr.set(''.join([translation.get(c, c) for c in inpstr.get()]))
    
root = tk.Tk()
inpstr = tk.StringVar()
outstr = tk.StringVar()

inpstr.trace('w', translate)

tk.Label(root, text='From Website:').pack(padx=5, pady=5)
tk.Entry(root, textvariable=inpstr, width=20).pack(padx=5, pady=5)

tk.Label(root, text='To Game:').pack(padx=5, pady=5)
tk.Entry(root, textvariable=outstr, width=20).pack(padx=5, pady=5)

tk.mainloop()

yes you understood my idea ^^ and that is what i want exactlly. thank you soo much bro i apreciate your help and your time
thank you ^^
Reply
#8
There may be ways to automate the entire thing. I know for sure that you can scape the web information so you wouldn't have to open the web page and copy the info manually. Translation is obviously easy. The tricky bit would be entering the info into your game. Not sure how that would happen. Is the game text based?
Reply
#9
(Feb-01-2021, 09:57 PM)deanhystad Wrote: There may be ways to automate the entire thing. I know for sure that you can scape the web information so you wouldn't have to open the web page and copy the info manually. Translation is obviously easy. The tricky bit would be entering the info into your game. Not sure how that would happen. Is the game text based?

yes, i will try to automate the entire thing with pyautogui . and for the game it's a 2D game , so i write in the text barre of the game /travel with the indications (x,y) and the character will go automatically to the position .
Reply
#10
str.maketrans() can create a translation table, which makes this look cleaner fyi. https://docs.python.org/3/library/stdtyp....maketrans

>>> translator = str.maketrans({
...   '[': '(',
...   ']': ')',
...   ';': ','
... })
>>> "[-31; -52]".translate(translator)
'(-31, -52)'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 7 1,617 Sep-12-2022, 02:55 AM
Last Post: AlexPython
  letter translator (or someting) Obsilion 4 2,462 Apr-28-2020, 12:40 PM
Last Post: deanhystad
  I want to filter out words with one letter in a string (pig latin translator) po0te 1 2,109 Jan-08-2020, 08:02 AM
Last Post: perfringo
  Trouble with Regex Translator skrivver99 3 2,770 Dec-15-2018, 03:55 PM
Last Post: Gribouillis
  Output discrepancy when building Translator skrivver99 17 6,675 Nov-26-2018, 01:22 AM
Last Post: ichabod801
  Help with pig latin translator DragonG 1 2,273 Nov-01-2018, 03:57 AM
Last Post: ichabod801
  PigLatin Sentence Translator Help 2skywalkers 7 5,815 Jun-23-2018, 12:46 AM
Last Post: 2skywalkers
  Pig Latin Translator RickyWilson 1 3,194 Dec-02-2017, 08:20 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020