This question already has answers here:
Why avoid while loops?
(13 answers)
Closed 9 years ago.
One of my teachers warned me not to use while in python. It is really strange for me as I have not found any articles on why to do so. What do you think on what could the grounds be?
Use the control statement that best suits your needs in each situation.
An advice like "Don't use while, only use for" boils down to "If the only tool you know is a hammer, all problems look like a nail."
Related
This question already has answers here:
Why does Python code use len() function instead of a length method?
(7 answers)
In Python, when should I use a function instead of a method?
(5 answers)
Closed 5 months ago.
I expect this question risks being closed as opinion-based, but it is a genuine question, and I assume there is a technical answer.
The builtin functions len and type confuse me, because I keep wanting to write
x.len()
or even
x.len
instead of
len(x)
This is probably because I use numpy x.shape frequently, and
I wondered what the rationale for this is? I assume it is something related to being dynamically typed, or maybe something related to None, but I couldn't figure it out. Are there certain situations where having these as members (properties or methods) doesn't make sense? Or maybe it is a speed consideration?
This question already has answers here:
What does "three dots" in Python mean when indexing what looks like a number?
(3 answers)
What does the Ellipsis object do?
(14 answers)
Closed 2 years ago.
So I have created a suffix tree using python and when I was printing my suffix tree, I came across one list that contains [...] at one of its indexes. I searched online and couldn't find anything regarding it. It would be really great if someone could explain to me that what does [...] mean in python. By the way, I'm using PyCharm IDE, not sure if it's an IDE specific issue. Cheers!
This question already has answers here:
How to obfuscate Python code effectively? [duplicate]
(22 answers)
Closed 3 years ago.
I have a script in .py format and random forest in pickle format and i should deliver it to a customer . He should not be able to read both.
If you really have to hide the code **, I recommend you to use an obfuscator
An example: https://wiki.python.org/moin/Pyarmor
PS: you have a similar question here: How to obfuscate Python code effectively?
Also, this is something I never did or explored, but through PYC-only distribution could be an alternative, but you must explore this by yourself.
Find out more at https://www.curiousefficiency.org/posts/2011/04/benefits-and-limitations-of-pyc-only.html
*** I know obfuscating code is not nice, but sometimes companies require it :/
This question already has answers here:
How to list all functions in a module?
(20 answers)
Closed 4 years ago.
I am new to python. This question might duplicate.
How to know the methods of lists. After search in google, its come to know there are more than 10 methods like append,insert , ,. is there any command/syntax to know the available methods.
lists is for example.
print(dir(list)) will give you the available methods on a class.
or help(list) in the REPL for nicer formatting, as suggested by #DeepSpace
This question already has answers here:
Why did Python 2.6 add a global next() function?
(3 answers)
Closed 6 years ago.
I'm new to python ,and just trying to figure out why two ways? any specific reason? which one is better?
I've tried searching but not able to find it.
The simplest answer is that the justification is similar for next(x) as it is for len(x). Fredrik Lund summarises Guido's response on that topic in this article.