How can I put giant writing in Python? - python

How could I make a word in giant text (for example “welcome” but giant)? I know that it's possible to change the console to make the font larger but I need it for just the word.

There are 2 ways to solve this problem
1 - Change the font in the python shell. Go to configure IDLE , go to the fonts tab and change the size value. Then apply the changes
2 - Using ASCII art. You can use ASCII art generators or use the python package pyfiglet(python version of figlet).
Example with pyfiglet
import pyfiglet
result = pyfiglet.figlet_format("Hello World")
print(result)
Pyfiglet also allows you to use many fonts , you can read their documentation for the everything else.
Hope this helps :)

Related

How to avoid Python to transform backlash (\) in less-than sign (<) in directory address?

I have a folder, which I'm trying to input in Python as a string, for example folder = r'C:\Users\Desktop' or folder = 'C:\\Users\\Desktop'
I'm then using pyautogui.typewrite(folder), but when I do so the directory name is pasted as C'<Users<Desktop
Do you know what is causing that and how can I solve this issue?
Thank you!
[Solution]
Combining both inputs from "SuperStormer" (thanks a lot!!) along with some additional research and adaptation I manage to solve the issue by:
Change the keyboard to English - looks like pyautogui emulates the typing of the keyboard, and it doesn't support any language other than english - this almost solved my issue, it solved the backslashes, but then the ":" started to become a "?", like 'C?\Users\Desktop'
Use pyperclip to paste string directly from keyboard - I did some simulations and that would have worked, except that I already had something on my clipboard that had to be used in a later step, and as I couldn't find a way to reference more than two clipboards at a time that didn't work right away, but after some workarounds based on that function I finally got to the solution

Removing a control character using Python

I have a script that processes the output of a command (the aws help cli command).
I step through the output line-by-line and don't start the actual real parsing until I encounter the text "AVAILABLE COMMANDS" at which point I set a flag to true and start further processing on each line.
I've had this working fine - BUT on Ubuntu we encounter a problem which is this :
The CLI highlights the text in a way I have not seen before:
The output is very long, so I've grep'd the particular line in question - see below:
># aws ec2 help | egrep '^A'
>AVAILABLE COMMANDS
># aws ec2 help | egrep '^A' | cat -vet
>A^HAV^HVA^HAI^HIL^HLA^HAB^HBL^HLE^HE C^HCO^HOM^HMM^HMA^HAN^HND^HDS^HS$
What I haven't seen before is that each letter that is highligted is in the format X^HX.
I'd like to apply a simple transformation of the type X^HX --> X (for all a-zA-Z).
What have I tried so far:
well my workaround is this - first I remove control characters like this:
String = re.sub(r'[\x00-\x1f\x7f-\x9f]','',String)
but I still have to search for 'AAVVAAIILLAABBLLEE' which is totally ugly. I considered using a further regex to turn doubles to singles but that will catch true doubles and get messy.
I started writing a function with an iteration across a constructed list of alpha characters to translate as described, and I used hexdump to try to figure out the exact \x code of the control characters in question but could not get it working - I could remove H but not the ^.
I really don't want to use any additional modules because I want to make this available to people without them having to install extras. In conclusion I have a workaround that is quite ugly, but I'm sure someone must know a quick an easy way to do this translation. It's odd that it only seems to show up on Ubuntu.
After looking at this a little further I was able to put in place a solution:
from string import ascii_lowercase
from string import ascii_uppercase
def RemoveUbuntuHighlighting(String):
for Char in ascii_uppercase + ascii_lowercase:
Match = Char + '\x08' + Char
String = re.sub(Match,Char,String)
return(String)
I'm still a little confounded to see characters highlighted in the format (X\x08X), the arrangement does seem to repeat the same information unnecessarily.
The other thing I would advise to anyone not familiar with reading hexcode is that each pair of hexes is swapped around with respect to the order of their appearance.
A much simpler and more reliable fix is to replace a backspace and duplicate of any character.
I have also augmented this to handle underscores using the same mechanism (character, backspace, underscore).
String = re.sub(r'(.)\x08(\1|_)', r'\1', String)
Demo: https://ideone.com/yzwd2V
This highlighting was standard back when output was to a line printer; backspacing and printing the same character again would add pigmentation to produce boldface. (Backspacing and printing an underscore would produce underlining.)
Probably the AWS CLI can be configured to disable this by setting the TERM variable to something like dumb. There is also a utility col which can remove this formatting (try col-b; maybe see also colcrt). Though perhaps really the best solution would be to import the AWS Python code and extract the help message natively.

the Georgian language in tkinter. Python

I can not write on a standard Georgian language in the Text widget. instead of letters writes question marks .
when no tkinter, ie, when writing code, Georgian font recognized without problems. Plus, if I copy the word written in Georgian and inserted in the text widget, it is displayed correctly.
this is elementary code that displays the text box on the screen, where I want to write a word in Georgian.
import tkinter
root = tkinter.Tk()
txt = tkinter.Text(root)
txt.pack()
root.mainloop()
the first image shows how the word is displayed when the selected Georgian language.
the second shot, when I write in the code in Georgian, and define in advance the value of text field. in this case, the text in the field is displayed normally.
Okay, so here is how I achieved it:
First, make sure you have a Georgian font installed in your computer; if there is no any, then go download one (I downloaded mine from here);
Now, go to your tkinter program, and add your font to your Text widget:
txt = tkinter.Text(root, font=("AcadNusx", 16))
NOTE 1: My font name that supports Georgian is AcadNusx, but yours can be different;
NOTE 2: If you have not imported Font, then import it at the beginning of your program;
NOTE 3: Do not change your computer's font to Georgian, because you have already changed it inside the program, so make sure it is set to English.
The best answer I can determine so far is that there is something about Georgian and keyboard entry that tk does not like, at least not on Windows.
Character 'translation' is usually called 'transliteration'.
Tk text uses the Basic Multilingual Plane (the BMP, the first 2**16 codepoints) of Unicode. This includes the Georgian alphabet. The second image shows that the default Text widget font on your system is quite capable of displaying Georgian characters once the characters are in the widget. So a new display font does not seem to be the solution to your problem.
('ქართული ენა' is visible on Firefox because FF is unicode based and can display most if not all of the BMP.)
It looks like the problem is getting the proper codes to tk without going through your editor. What OS and editor are your using. How did you enter the mixed-alphabet line similar to
txt.insert('1.0', 'ქართული ენა') # ? (I cannot copy the image string.)
How are you running the Python code? If you cut the question marks from the first image and insert into
for c in '<insert here>': print(ord(c))
what do you see?
You need a 'Georgian keyboard entry' or 'input method' program (Google shows several) for your OS that will let you switch back and forth between sending ascii and Geargian codes to any program reading the keyboard.
Windows now comes with this, with languages activated on a case-by-case basis. I already had Spanish entry, and with it I can enter á and ñ both here and into IDLE and a fresh Text box. However, when I add Georgian, I can type (randomly ;-) ჰჯჰფგეუგსკფ here (in FireFox, also MS Edge) but only get ?????? in tk Text boxes. And these are actual ascii question marks, ord('?') = 63, rather that replacements for codes that cannot be represented. Japanese also works with tk-Text based IDLE. So the problem with Georgian is not generic to all non-latin alphabets.

Sublime Os X output window word-wrap

I am coding Python using Sublime 2 in OS X, but whenever I run cmd+B the output is long and not word wrapped. I enabled word-wrap but I think it's only for editor itself. Any solution is much appreciated
Cmd-B is just a convenience wrapper around a terminal execution. There are two ways to prevent the line from overflowing:
1) If your output is a string, which I think it is, you can use something like the solution in this thread. Example:
char_size = 80
pieces = [my_long_str[x:x+char_size] for x in range(0,len(my_long_str),char_size)]
for piece in pieces:
print piece
This will print every 80 characters worth of content on a new line.
2) If you're output is a list, you can use the pprint module to pretty-print your list by listing each element on different lines. Check out the pprint.pprint module in particular here.

Modifying Windows Ctrl+Del behavior across different programs

I would like to override the behavior of the Ctrl+Del or Ctrl+Backspace in various programs in Windows 7 which do not delete whole words before or after caret by default. Eg: Notepad displays a box looking character (not sure which one) when pressing Ctrl+Backspace.
Is there a fix for this in Windows 7?
Could i use Python, Autohotkey, or anoother language to override this behavour? Eg: find the position of the cursor/caret and delete the following whole word.
AutoHotkey will do what you want.
#IfWinActive ahk_class Notepad
^Delete::SendInput something else
#IfWinActive
You can find the ahk_class with Au3 Window Spy, and a list of keys in the docs.
delete whole words before or after caret
^Del::SendInput ^+{Right}{Delete}
^BackSpace::SendInput ^+{Left}{Delete}
This relies on Ctrl+Shift+← selecting the word to the left of the caret, and Ctrl+Shift+→ selecting the word to the right of the caret.
If you only want to enable it for specific programs, you can follow the suggestions of the other answers, for example using #IfWinActive coupled with ahk_class, like so:
#IfWinActive ahk_class Notepad
^Del::SendInput ^+{Right}{Delete}
^BackSpace::SendInput ^+{Left}{Delete}
I think this will give you a start...
^Del::
SetTitleMatchMode, 2
IfWinActive, Application title ; Use windows spy
{
Send, xyz ; modified behaviour
}
Else
{
Send, ^{Del} ; Original behaviour
}
Return

Categories

Resources