What does square bracket mean in python paramters - python-3.x

Hello I'm new to python and I'm trying to learn OpenCV.
When I check the API references for OpenCV I came across this types of parameter description.
cv2.imread(filepath[, flags])
What does the "[, flags]" part mean? I know it takes in two variable, which is filepath and flags, but I don't know the meaning of the square bracket.
Any help is appreciated!

Related

Python 3 Tips to Shorten Code for Assignment and Getting Around TextIO

I've been going through a course and trying to find ways to shorten my code. I had this assignment to open a text file, split it, then add all of the unique values to a list, then finally sort it. I passed the assignment, but I have been trying to shorten it to learn some ways to apply any shortening concepts to future codes. The main issues I keep running into is trying to make the opened file into strings to turn them into lists to append and such without read(). If I don't used read() I get back TextIO errors. I tried looking into it but what I found involved importing os and doing some other funky stuff, which seems like it would take more time.
So if anyone would mind giving me tips to more effectively code this that are beginner friendly I would be appreciative.
romeo = open('romeo').read()
mylist = list()
for line in romeo.split() :
if line not in mylist:
mylist.append(line)
mylist.sort()
print(mylist)
I saw that set() is pretty good for unique values, but then I don't think I can sort it. Then trying flip flop between a list and set would seem wacky. I tried those swanky one line for loop boys, but couldn't get it to work. like for line not in mylist : mylist.append(line) I know that's not how to do it or even close, but I don't know how to convey what I mean.
So to iterate:
1. How to get the same result without read() / getting around textIO
2. How to write this code in a more stream lined way.
I'm new to the site and coding, so hopefully I didn't trigger anyone.

GDScript String format with an array

I'm learning Godot and GDScript as an absolute beginer. For that I follow a course where the instructor make a simple code to format a string with values contained in an array. Here is his code :
But when I write the exact same code I have the following error "unsupported format character in operator '%'"
Can someone explain me what's wrong ? The only difference I can see is that the tutorial was writtenn on Godot 3.1 and I'm on 3.2.3
You're missing the second format specifier in story. Should be:
...ate %s flavoured...
What you're doing is called String Interpolation. As a reminder, all of the % inside your string need to have a specifier next to them. %s works for now, because you're embedding strings.
The documentation on the other specifiers for future reference: https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_format_string.html#format-specifiers

Print a variable with index (eg. x_1)

i am trying to print variables with indices.
The goal is to write something like:
x_1 + x_2 = 3 + 1 = 4
The problem is, that variables just like x_1 does not show an index. It shows the underscore itself.
/* works fine */
print(x_1)$
x_1;
/* Does not work */
ostream: make_string_output_stream()$
printf(ostream, string(x_1))$
get_output_stream_string(ostream);
Output of the code above
Converting "x_1" into a string destroys the underscore, but you need a string for the method printf().
Are there workarounds for this?
What to do here probably depends somewhat on what goal you need to achieve with this. Can you say more about the larger goal you are working toward?
In order to generate output which has typesetting instructions in it, you can call the tex or tex1 function to generate TeX output. If that needs to be displayed in a web page, I believe you can make use of the MathJax Javascript library. Sorry, I don't know more about MathJax.
You should probably write x[1] instead of x_1. Displaying x_1 with a subscript 1 is a convenience -- the rest of Maxima doesn't know much about it.
EDIT: There is also an add-on package to output MathML; there might be two such packages, I would have to check. If MathML could help solve your problem, I will look into it.

How to place latex-like mathematical formulas (e.g. via mathjax) in Haskell Diagrams?

I am attempting to place latex-style math formulas into a haskell diagram.
The documentation pages
http://projects.haskell.org/diagrams/doc/manual.html#essential-concepts
and
http://projects.haskell.org/diagrams/doc/tutorials.html
suggest that one can use something called 'mathjax' to achieve this.
Is there an explanation or example somewhere of how to actually code this?
Attempting to follow the documentation at those links, my best guess for how would be something like:
mathDiagram :: Diagram B
mathDiagram = stroke $ textSVG "`2 + \sqrt{\pi}`:math:" 1
But this of course gives an error:
induction.hs:13:35: error:
lexical error in string/character literal at character 's'
You can do this using the diagrams-pgf backend. Just use the text function and put dollar signs around your text. Also, see here for an explanation of how to include diagrams in a LaTeX document: http://projects.haskell.org/diagrams/doc/latex.html .

hiding variable or limit lenght of it in python - without manipulating it's value

I have a variable x, which has a string of 500 and more charhacters.
The problem is, it is very annoying when you do coding and this long string takes half of the screen.
My question is: is it possible to hide the value of variable, with out manipulating it's value? Open for any solution to solve problem. Thank you.
Its a little backwards of a solution but you can call X in a separate program and import it to your main program.
Importing variables from another file?
Here is a link to how to do that.
Another solution would be to call it at the top of your program and just type everything below it.

Resources