how to make an input appear at the bottom of the terminal/console?
with
import Console
a = Console.getconsole()
a.text(0,-1,'YOU CAN PRINT TEXT IN THE BOTTOM ROW OF CONSOLE')
you can print text in the bottom of the console, but you can't input. how can you make an input at the bottom of the console?
Click to see image
More detailed picture
Im getting answers that are not what im searching exactly for but i understand them. Other option for me it would be have 2 consoles and whain i imput something in console1 smething happens to console2.
Functions or libraries are not available to fulfill the desired output then there is always a way to achieve the result by logic.
print('abc')
a="\n"*10
x= input(a+'Enter here :')
print(x)
The console (or terminal) in python works in a way that it goes to the next available line. However, you can use the get_terminal_size() method to do complete the task.
What one could do is add many blank lines like this:
import os
# Get the size of the terminal
size = os.get_terminal_size()
print('number of rows', size.lines)
a="\n"*(size.lines - 2)
name= input(a+'what is your name?')
print('hello', name)
which would look like this:
Related
I Made a config.ini for my Python project
now i be able to save values and put them as print or something inside my Code
This is working for all Statik things like Device= str....ConfigParser and is shown in print (Device)
But it is not working when i give that code or Variable to PixelmatchesColor if i do this for X,Y Cords its get an error cant read or cant use is no right parameter. When i use this inside Print all works well and shown inside Promt
If there is no Way to make a Config File that works with pyautogui pixel match color i will try this code How can pyautogui.pixelMatchesColor not work properly?. It looks for an Image and then it uses pixelmatch to verify. i only need to look at a Bell and check if they is on Screen if it is found (Color or IMG) all is fine if not restart after time Browser
i'm not a professional coder and i'm so sorry for my english :)
i hope you understand.
I'm trying to automate part of my job.
i have to create dwg; every layer for me is a sheet (like A4 paper), for that reason i have to change layer and import specific dwg/dxf from my repository symbol.
For example i have to:
(start new project)
open newproject.dwg
(paste dwg)
import C:\repository_cad\symbol1.dwg in layer n°3 with coordinate X 100 Y 200.
(write text in the middle of symbol)
write "SYMBOL_1" layer n°3 coordinate X 150 Y200 alignment center.
(insert logo image)
import C:\repository_cad\image1.jpg in coordinate X 10 Y 20
i'm trying to use pyautocad, but i cant find a command for import dxf, and i dont find information about changing layer.
i find out only the command for draw the line, circle ecc, but if i have to re-draw all my repository by python i need to much time, i hope is possible copy draw from another dwg and paste it in my new dwg.
can someone give to me a little help with these 3 command?
maybe is not possible making this stuff on pyautocad? is there other library for python?
i read the docs but i dont see info about some import function.
so, i tried:
from pyautocad import Autocad, APoint
acad = Autocad(create_if_not_exists=False)
acad.prompt("Hello, Autocad from Python\n")
print (acad.doc.Name)
and it's works, on autocad terminal i can see "Hello, Autocad from Python"
in the Docs i find out how write a autocad-command from python.
The function is:
prompt()
i tried:
acad.prompt('-INSERT') #-INSERT is the autocad command for import dxf or dwg
acad.prompt('C:\SPAC\Librerie\Elettr\02-15-04.dwg')#this is the path of the cad
acad.prompt('-15 -15') #coord X Y of the point where i want to paste
acad.prompt('1') # 1 is the scale factor in X
acad.prompt('1') # 1 is the scale factor in Y (autocad askt first in X and after in Y
acad.prompt('0') #degree of rotation
at this point i havent error on python and no error on autocad terminal, but the draw not appear on cad
thanks
Max
acad.prompt() will just echo the string to the command line. What you are looking for is acad.doc.SendCommand(), e.g.
acad.doc.SendCommand('-INSERT ')
Notice there is a blank space after the autocad command, that stands for to activate the command.
I'm trying to get the number of audio tracks in a video file. The video have multiple tracks (like different, selectable languages for the same movie.) So if there are three optional languages for the video, i'd like to get the number 3 in the end, no matter if the audio is in stereo, mono or in 5.1.
So far I tried to do it with moviepy. I found only the function "reader.nchannels", but that counts only the first audio track's left and right channel, so I get the number 2 every time.
The code right now is really simple, it looks like this:
from moviepy.editor import *
from moviepy.audio import *
clip = VideoFileClip(source)
audio_tracks = clip.audio.reader.nchannels
I also tried to get every info from the audio like this:
audio = AudioFileClip(source)
tracks= audio_tracks.reader.infos
The output for this looks like this:
"'audio_found': True, 'audio_fps': 48000}"
tburrows13, thanks for pointing to the right direction.
I was able to get the numbers of audio channels and store it in a variable through a py script. Maybe this is not the most elegant solution, but it works, so here it is, if someone needs it. You have to import "subprocess" and use ffprobe with it. ffprobe comes with ffmpeg.
To get the number of streams the command goes like this:
ffprobe <filename here> -show_entries format=nb_streams
This will give you the number of streams in the file, not just the audios, but the video streams too. There is an option to get the data only for the audio streams, but this was not necessary for my project.
You can call this command through a python script. The command needs to be a string, you can store it in a variable too. To get and store the output of this commmand in an other variable you can use this:
variable = subprocess.check_output(subprocesscommand) # subprocesscommand is the string version of the command wrote above.
If you print out now this variable the output will be something like: b'[FORMAT]\r\nnb_streams=3\r\n[/FORMAT]\r\n'
Now you just need to slice the string value, to get the number of the streams.
Thanks again for your help!
I want to replace the text in a textbox in Powerpoint with Python-pptx.
Everything I found online didn't work for me and the documentation isn't that helpful for me.
So I have a Textbox with the Text:
$$Name 1$$
$$Name 2$$
and I want to change the $$Name1 $$ to Tom.
How can I achieve that?
A TextFrame object defined in python-pptx helps in manipulating contents of a textbox. You can do something like:
from python-pptx import Presentation
"""open file"""
prs = Presentaion('pptfile.pptx')
"""get to the required slide"""
slide = prs.slides[0]
"""Find required text box"""
for shape in slide.shapes:
if not shape.has_text_frame:
continue
text_frame = shape.text_frame
if "Name 1" == text_frame.text:
text_frame.text = "Tom"
"""save the file"""
prs.save("pptfile.pptx")
Try this:
import pptx
input_pptx = "Input File Path"
prs = pptx.Presentation((input_pptx))
testString = "$$Name1 $$"
replaceString = 'Tom'
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
if(shape.text.find(testString))!=-1:
shape.text = shape.text.replace(testString, replaceString)
if not shape.has_table:
continue
prs.save('C:/test.pptx')
Ok thank you. I just found out, that my PowerPoint example was totaly messed up. No everything works fine with a new PowerPoint blanked
In order to keep original formatting, we need to replace the text at the run level.
from pptx import Presentation
ppt = Presentation(file_path_of_pptx)
search_str = '$$Name1$$'
replace_str = 'Tom'
for slide in ppt.slides:
for shape in slide.shapes:
if shape.has_text_frame:
for paragraph in shape.text_frame.paragraphs:
for run in paragraph.runs:
print(run.text)
if(run.text.find(search_str))!=-1:
run.text = run.text.replace(search_str, replace_str)
ppt.save(file_path_of_new_pptx)
Since PowerPoint splits the text of a paragraph into seemingly random runs (and on top each run carries its own - possibly different - character formatting) you can not just look for the text in every run, because the text may actually be distributed over a couple of runs and in each of those you'll only find part of the text you are looking for.
Doing it at the paragraph level is possible, but you'll lose all character formatting of that paragraph, which might screw up your presentation quite a bit.
Using the text on paragraph level, doing the replacement and assigning that result to the paragraph's first run while removing the other runs from the paragraph is better, but will change the character formatting of all runs to that of the first one, again screwing around in places, where it shouldn't.
Therefore I wrote a rather comprehensive script that can be installed with
python -m pip install python-pptx-text-replacer
and that creates a command python-pptx-text-replacer that you can use to do those replacements from the command line, or you can use the class TextReplacer in that package in your own Python scripts. It is able to change text in tables, charts and wherever else some text might appear, while preserving any character formatting specified for that text.
Read the README.md at https://github.com/fschaeck/python-pptx-text-replacer for more detailed information on usage. And open an issue there if you got any problems with the code!
Also see my answer at python-pptx - How to replace keyword across multiple runs? for an example of how the script deals with character formatting...
I have a 2D shell part containing a number of shell faces. I would like to extract one different sketch for each of the faces in the part. So far I know how to create a single sketch containing all the shell faces information but this is not what I want. I would like to know how to create one sketch per shell face. This is what I have done (not right).
stest= model.ConstrainedSketch(name='__polyTest__',sheetSize=2000.0)
mdb.models['Model-1'].parts['Result'].projectReferencesOntoSketch(filter=
COPLANAR_EDGES, sketch=mdb.models['Model-1'].sketches['__polyTest__'])
Many thanks for your help.
Open your part in the current viewport and try this:
from part import *
from sketch import *
p=session.viewports[session.currentViewportName].displayedObject
currentModel=mdb.models[p.modelName]
for faceNum,face in enumerate(p.faces):
try: # Will only work on valid sketch planes. Must be a flat face
t = p.MakeSketchTransform(sketchPlane=face, sketchUpEdge=p.edges[0],
sketchPlaneSide=SIDE1, origin=(659.077803, 0.256062, -816.16))
s = currentModel.ConstrainedSketch(name='__profile__',
sheetSize=834.36, gridSpacing=20.85, transform=t)
edgeList=[p.edges[edgeNum] for edgeNum in face.getEdges()]
p.projectEdgesOntoSketch(sketch=s, edges=tuple(edgeList))
currentModel.ConstrainedSketch(name='Sketch-face' + str(edgeNum), objectToCopy=s)
except:
pass