Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Is there a recommended reference manual for python that's better than the official docs? I'm an experienced programmer (PHP, C#, javascript, and some C most recently), and I find the python manual pretty lacking compared the PHP manual and MSDN. In particular, the official docs never seem to tell me what errors can happen if I pass in something invalid, and there's apparently not a way to navigate within a module.
Take the os module for example. There's no list of constants or methods I can call on that page, so I have to Ctrl+f for "stat(" until I find it. Then, once I do find it, it doesn't tell me what to expect if I call stat with a directory that doesn't exist, so I just have to try it in a terminal and see what happens.
This seems wildly inefficient… how do python programmers deal with this?
In practice, you either make a quick test program to check the behavior, or read the source code. Much of the Python standard library code is fairly clearly written and in fact rather self-documenting, so it's standard practice to refer to it when you need to know the nitty-gritty details of how something works.
One exception: with low-level system functions such as many of those in the os module, the functions map directly on to their C namesakes for the underlying platform. So if you need to know about the behavior of Python's stat, you look up the reference documentation for your platform's native C stat call. In these cases the Python library docs often only explain the basic purpose of the function and how it differs from its C equivalent, if at all.
I don't think I ever had the same feeling towards the python docs as you do but I did some times need to go out of my way some times for a better understand of how a part of python works. Though that is how most language are. Python is a quick and easy language to learn which requires less time on docs and more time programming. Also python's user base isn't as large as PHP. PHP has people constantly giving examples and details on certain functions daily.
Another great thing about python is its interactive shell to test things out. Just my idea of programming you learn more by doing then seeing. So if you're ever interested in testing something you don't need to drag through compiling, just write a quick script in the interpreter. the interpreter also has reference tools. Example dir(<identifier>) and help(<identifier>) for module, clasa or function needs.
Any way enough defending my favorite language, pyDoc is a little useful tool to help you get what you need from python.
pydoc is a tool that comes with Python that can be used for viewing
and generating Python documentation.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 21 days ago.
Improve this question
I recently started developing games on Godot after 3 months of Python experience. Is it good to learn Python before jumping into GDscript? If not, how different are the two? Is it okay to first learn Python in preparation?
Thank you! :)
I decided I should watch the official GDscript tutorials that the Godot channel put out, I have not finished it entirely as it is very long, so I was wondering if someone on the forum could answer :)
Is it good to learn Python before jumping into GDscript?
It is not necessary. It is arguably good, but not because of it being Python specifically. Any prior programming experience will transfer well.
If not, how different are the two?
They have similar syntax. Keywords are different.
In general it is easy to translate algorithms from Python to GDScript. However, it might result in a suboptimal GDScript/Godot solution.
A common experience among beginners has been implementing things in GDScript to later discover that Godot already have a built-in way to do it that is both more convenient and more efficient (I'm not saying this is always the case, but that it is very common). Please notice that is not so much learning GDScript, but learning Godot.
Don't expect any advanced Python to work on GDScript. The reason being that GDScript semantics are closer to Java or C#.
I want to mention that in GDScript you are free to specify types or omit them from your code (in which case it behaves as a dynamically typed language). In general I encourage to use types, it allows for static analysis (and starting from Godot 4 it should give you better performance too).
Is it okay to first learn Python in preparation?
You can learn whatever. Learning Python first is OK. It will not hinder your experience with GDScript.
With that said, I want to point out that GDScript is a good entry level programming language. You can jump into GDScript without prior programming knowledge.
Is there any good sources such as books or writing that I should refer to?
While it is off-topic to ask for learning material on this site, it is OK to recommend…
There is a canonical answer: Tutorials and resources.
I decided I should watch the official GDscript tutorials that the Godot channel put out, I have not finished it entirely as it is very long
Do as you wish. People have different preferences for learning.
Some of us rather have a project to motivate us, and learn the things we need to get it done. Other prefer to explore and experiment the options. Others prefer to have tutor that guide them.
It is all valid.
If I were you, I would go with GDScript basics and jump in. But I'm not you.
so I was wondering if someone on the forum could answer :)
This is not a forum. This a Q&A site. Open ended conversations do not work well here.
With that said, I would like to point you to: the official Godot forum. See the Godot's community page.
I would also want to point out that despite GDScript being the intended and preferred way to use Godot, you don't have to. Yes, you might even use Python. And yes people coming from Unity might use C#. See using different programming language in godot game engine?. If you plan to do something like that, I would still encourage to give GDScript a try.
Godot documentation is very clear, well organized and straigthforward.
You definately should take a look at it. If you just casualy read the General and Getting Started section from the navbar you probably gonna learn lots of things. Godot Docs
If somehow you still are doubtfull about GDScript, the docs also have a section under the Scripting link dedicated to it's introduction and other stuff. GDScript Docs
Have fun! :)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a vague memory of this question being asked before somewhere in cyberspace but I can't find it again.
Say I have a file with a bunch of functions (and or classes) defined, but I know that some of them are not used anywhere in my project. Is there a tool to scan through my project to see which functions aren't being used?
I know I can do this individually for each function, using Pycharm for example, but I don't know of a way to do this for all functions in a file. It feels like there must be a tool for this, but I don't know of one.
EDIT
I know there are edge cases of code, as pointed out by #deceze, that make this sort of usage checking impossible in general. But I'd be happy with a tool that works 99% of the time. The rest can be caught by unit tests for example, and manually handled.
I don't know about any tool that explores your whole project but you could easily make one in few lines of code by using the jedi library.
There is jedi.Script.usages which is exactly what you want here, the tool would do something like:
Create a jedi environment using your python interpreter of choice (this way will have information about sys.path
Walk over the project files you want to analize and extract the functions you want to check usages from (glob, os.walk, custom cli, ...)
On each file, you just need to extract the functions you want to analize (in your parser you store the locations as line/columns pairs)
Create a jedi script with the previous location and call usages and then store the results in a dictionary
Profit
PS: the most "tricky" step would be the one that extract functions from your python files but I guess this could also be done with jedi instead using another builtin python parsers, here's an untested piece of code:
for definition in jedi.names(source, all_scopes=True, definitions=True, references=True):
if definition.parent().type == "function": # The name is located in a function ...
ass = definition.goto_assignments()
if len(ass) > 0 and ass[0].parent().type == "function": # ... and is assigned to in a function
print("Found a local variable:", definition.name)
Extracted from this github issue
Coverage.py - used it recently to show my test coverage. But it can be used in other contexts as well
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Edit<<<<<<<
The question is:
-How do you launch C code from python? (say, in a function)
-How do you load Java code into python? (perhaps in a class?)
-Can you simply work with these two in a python program or are there special considerations?
-Will it be worth it, or will integrating cause too much lag?
Being familiar with all three languages (C, Java and Python) and knowing that Python supports C libraries, (and apparently can integrate with Java also) I was wondering if Python could integrate a program using both languages?
What I would like is fast flexible C functions while taking advantage of Java's extensive front-end libraries and coordinating the two in Python's clean, readable syntax.
Is this possible?
EDIT---->
To be more specific, I would like to write and execute python code that integrates my own fast C functions. Then, call Java libraries like swing to create user interface and handle networking. Probably taking advantage of XML as well to aid in file manipulation.
To be more specific, I would like to write and execute python code that integrates my own fast C functions. Then, call Java libraries like swing to create user interface and handle networking. Probably taking advantage of XML as well to aid in file manipulation.
Integrating C code into Python is quite easy using modules such as ctypes or cffi.
Integrating Java code into Python is not simple, and is likely well beyond your ability. There are plenty of very capable user interface, networking, and XML processing libraries available for Python; you don't need Java to do any of that.
For C, you can use ctype module or SWIG.
For Java, Jython is a good choice.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
It is often stated that RPython is an unpleasant language to program in, for example, here, here, here or here.
However, for example here in the original paper about RPython, it says quite the opposite:
The result is a language that is more expressive than C# and Java, but
which does not compromise runtime efficiency. RPython was initially
designed for the specific purpose of implementing PyPy [25] (a Python
interpreter written in Python), but it has grown into a full-fledged
language in its own right.
Currently, RPython can be used in many contexts: to develop
stand-alone programs, such as the Standard Interpreter itself; to
write highly efficient extension modules for CPython, which could only
be written in C in the past; to develop dynamic web applications
without the need to write JavaScript code; to produce efficient
libraries of classes and functions to be used by other .NET and Java
programs. In particular, RPython can be the ideal companion for all
those CPython, IronPython and Jython developers that so far have been
forced to write the parts of their programs that need high performance
in C, C# or Java.
A related question for using RPython as a general purpose language is also here. I was also wondering about using RPython as a replacement for Cython. A related question is here. There is also the RPythonic project.
Why is it that people recommend against using RPython?
from here:https://mail.python.org/pipermail/pypy-dev/2013-June/011503.html
"
When people look at RPython, an obvious feature is that it is
syntactically identical to Python. "RPython must be an easy language,
given that it has got the syntax of Python, which is easy". This is a
common misconception. In fact, pleasing the automatic type inference
process can be difficult. It requires the programmer keeping in his
head the global types of his whole program, and carefully writing code
according to these implicit types. The process is much harder for
newcomers, which don't have any written-down example to learn how to
manipulate the types --- precisely because they are implicit.
"
I have made one file conversion program using RPython toolchain. Simple buffered file input and output. I can't imagine with my skills easier language to make such a fast, reliable, low bugs program.
What works and what doesn't is not well documented but once you find things out it is really nice set of tools to make small, fast and reliable programs.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am amazed by how Expect (TCL) can automate a lot of things I normally could not do.
I thought I could dig deeper into Expect by reading a book, but before I do that I want to ask if there are other solutions/languages that could do what Expect does?
Eg. I have read that people compare Expect with Awk and also Perl.
Could Awk and Perl do the same thing?
How about other languages like Python and Ruby?
Is Expect the de-facto automation tool or are there other solutions/languages that are more superior?
There's more to it.
Bluntly, the original Expect--the Tcl Expect--is the best one. It better supports "interact" and various pty eccentricities than any of its successors. It has no superior, for what it does.
HOWEVER, at the same time, most Expect users exploit such a small fraction of Expect's capabilities that this technical superiority is a matter of indifference to them. In nearly all cases, I advise someone coming from Perl to use Expect.pm, someone familiar with Python to rely on Pexpect, and so on.
Naive comparisons of Perl with "... Awk and also Perl" are ill-founded.
In the abstract, all the common scripting languages--Lua, awk, sh, Tcl, Ruby, Perl, Python, ...--are about the same. Expect slightly but very effectively extends this common core in the direction of pty-awareness (there's a little more to the story that we can neglect for the moment). Roughly speaking, if your automation involves entering an invisible password, you want Expect. Awk and Perl do NOT build in this capability.
There are other automation tools for other contexts.
Check out Expect for Perl
ajsie asks, "Which other automation tools are you talking about?"
I'll answer a different question: "which other contexts do I have in mind"? The answer: any interactive environment OTHER than a stdio one. Expect is NOT for automation of GUI points-and-clicks, for example. Expect is also not available for Win* non-console applications, even if they look as though they are character-oriented (such exist).
An exciting counter-realization: Expect is for automation of wacky equipment that permits control by a term-like connection. If your diesel engine (or, more typically, telecomm iron) says it can be monitored by hooking up a telnet-like process (even through an old-style serial line, say), you're in a domain where Expect has a chance to work its magic.
Check out Pexpect for Python