Is it possible to make key words in python [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I was wondering if it was possible to make a keyword similar to 'and', or if it is part of the python compiler?
Thx

You can file a PEP (although good luck getting your new keyword accepted); or you can implement it yourself. Other than that, no: python doesn't allow dynamic syntax.
What you can do is look at the magic methods which are called by operators. Redefining these is sometimes handy. Pathlib makes it possible to do this:
from pathlib import Path
Path("a/b") / "c/d.txt"
And they didn't have to introduce any new operators or keywords, even though the usual meaning of / is division, not concatenation.

Related

TypeError: 'fn' must be callable (Prefect - Python) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
I'm starting to leart some prefect + python and I'm facing a strange error at the very beginning with a very easy script:
I have already tried it in two diferents PC.
It looks like you've installed Prefect 2, but are following instructions for Prefect 1.
I recommend starting with the first steps tutorial in the Prefect docs: https://docs.prefect.io/tutorials/first-steps/
the way with statements work is that the variable you're defining only exists within the indented code block underneath the with statement itself. The end of your code should be:
with Flow("prueba 1") as flow:
carga()
flow.run()

How to make a calculator discord bot? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
How to make a discord bot so when I input the following it calculates it:
INPUT:
2.2x100 2.8x100-10%
OUTPUT:
output should be the result of the following:
2.8100 - 2.2100 and then minus 10% of that,
(that equation is subject to change)
How would I do this?
This is not an easy task (if you don't want to be unsafe and eval() code).
You need an infix parser that takes into account order of operations (priorities). If there are parenthesis in your operation, it will be even more complex.
You will then need to evaluate the result with a function that executes an abstract syntax tree generated by the parser (AST).
There is probably libraries that make this easier without being unsafe, but make a google search about all the terms I talked about so you can learn more.
EDIT: also take a look at this link. Not beginner stuff.
Infix Calculator Expression Parser
EDIT 2: Just in case you want the easiest solution with eval(), be careful. A skilled attacker can destroy your computer with malicious code. If you just eval() whatever is sent to the bot, they could really destroy / take control of your computer. Be careful.

Is there any easier way to do this? Pycharm query [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 12 months ago.
Improve this question
So I was making my voice assistant made with python more efficient but I'm stuck at a time-consuming problem.
I've given the image. Is there any way to replace the variable "cmd" with the variable "query" in all lines with just some clicks? Changing the variable one by one takes up a lot of time.
In Pycharm you can highlight an occurrence of cmd in your code, right click on it, select Refactor, Rename.
You can now choose a new name and a scope for the files in which Pycharm should search and carry out the replacement in. Make sure you know the implications of where this replacement will be done, because you could accidentally refactor the term "cmd" in locations you didn't mean to.

Python docx documenation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am looking for resources that help me interpret python documentation effectivley. In particular, I am reading through the pythondocx module documentation, but am finding it hard to understand some sections.
As an example, when I read the Style Objects Section
, I am confused by lines such as class docx.styles.styles.Styles and what it is actually saying.
Any ideas on what I can do the to interpret documentation better?
I honestly think reading pythondocx module documentation is a bit of overkill.
The hard part of reading python documentation is understanding the specific logic of how objects and builtin's are organized in python. The best place to start, IMHO, is the index Python 3.8.1 documentation together with standard library and collections.
Even if you had studied other common languages before, like Java and C#, their API's are laid out in a different style. Each takes its own time for the reader to get used to. The python docs were written to be self-explanatory and after an initial learning curve that isn't especially steep the docs start making lots of sense.

How to make this gaema demo running on google-app-engine? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
This is the package which has a webapp demo in it.
However, when I login use this demo, I get an error.
How to make this demo running on the gae-launcher?
Looks like a bug in gaema.
The line that's failing is trying to urlencode a dictionary of arguments that get passed to the OpenID endpoint. One or more of the values, perhaps your first or last name, has non-ASCII characters.
You might be able to work around it by replacing instances of this:
urllib.urlencode(args)
With this:
urllib.urlencode(dict([(k, args[k].encode('utf-8')) for k in args]))
For a more permanent fix, I would report the issue here:
http://code.google.com/p/gaema/issues/list

Categories