I am new pyomo user. I want to learn that is there any document or way to see all attributes, methods and functions of pyomo? Same issue for CBC.
Source-level documentation is not currently supported for Pyomo. The Pyomo developers have discussed whether/how to make this a priority, but this is not yet the focus of the team.
From the interactive Python shell, you can import a module and then do a help() on it to see documentation included in the module itself:
>>> import pyomo
>>> help(pyomo)
You can also use the dir() command to see a list of all attributes and functions that are in the module:
>>> dir(pyomo)
But I have to ask -- what is wrong with the online documentation at www.pyomo.org? It seems like a very nice homepage for the project.
Related
I am trying to figure out how to list out all the standard library functions/methods (still learning the difference, I'm a noob). So I get how to import a module and use dir() and help(). These have been a great help and when I try to rewrite a program I learned to write and I get lost I try to use the dir() and help() to spark my memory.
However, for example, I was re-looking through some code and I had .replace() and I was scouring through my imported modules to find it and then found out it's in the standard library and a sub-part of the str() function. Is there something I can type into dir() that will spit out str()?
How can I print out all top level built in function/methods like I would when I do dir(re)?
I've tried re-wording this question in search engines several ways and I can't find anything and the results get muddied with "python list _____".
Thanks so much!
Is there something I can type into dir() that will spit out str()?
dir() on a value of that type.
dir('hello') # string methods
dir(5) # integer methods
dir([]) # list methods
Ah, I never tried typing just "dir()" that listed I could put in dir(__builtins__) and that is what I was looking for. I'll leave it here in case someone else is a noob too and knows where they can start. Just start with dir() and go down the rabbit hole!
I have I small module that I use inside one of my projects. Now I decided to place it on github so now I am writing some docstrings and cleaning the code.
I have a composition of 2 classes so the initialization looks like this:
foo = Class_1()
bar = Class_2(param1=foo)
I know that the first argument to the Class_2 has to be an instance of Class_1 or the code won't work. But it may be clear only for me as I wrote code of Class_2, but when using module as API it may be unclear for a user that param1 has to be an instance of Class_1. If someone will use bar = Class_2(param1='foo'). The trackback will be bad and it will be impossible to understand what happened. So the question is: do I need to check in my __init__ that isinstance(param1, Class_1) and if no raise an excaption with an appropriate message, or writing good documentation is enough?
This is very opinion-based (not great for StackOverflow in particular) - but in my opinion, you should do both.
On the one hand, using isinstance() and exception-handling are both good defensive-coding practices.
On the other hand, inline documentation is nice. Per the Python developer guide:
The markup used for the Python documentation is reStructuredText, developed by the docutils project, amended by custom directives and using a toolset named Sphinx to post-process the HTML output.
Some IDEs, such as JetBrains PyCharm, are configured to automatically pick up well-formed reST docstrings and perform automated type-checking based on those conventions (which I've found to be really useful). See also: PEP 257 and What is the standard Python docstring format? for details.
I am trying to use the rubypython gem. Not sure how to call standard python functions like len and set. In the python examples I see len(text3) and set(text3).
How do I call these in rubypython?
Here is the link to rubypython: http://rubypython.rubyforge.org/
Well, my Ruby knowledge is limited, and my knowledge of the rubypython gem is non-existent. However, I do know the standard functions you refer to a part of the __builtin__ module, which is automatically imported into the python namespace. Fortunately, there's nothing preventing you from importing it explicitly again (which is perfectly safe in Python). You then might be able do something like __builtin__.set(). No guarantees, though.
RubyPython::PyMainClass has a public instance method builtin()
You can use that to call the standard functions.
The python-couchdb package (used as import couchdb) provides a db.view() function to access a couchdb "_view", but how do you access a "_show" or "_list" function?
This was asked before (http://stackoverflow.com/questions/5491851/couchdb-and-python-how-to-use-show-and-list-functions) and 1 of the authors said that it was now included in the library, but he doesn't mention HOW to use it (db.show() doesn't work) and I can't find any documentation for it online.
Can anyone let me know the function/method - or - point me at a page that explains how to do it. I'm particularly interested in "_show".
Currently, you need to get couchdb-python from repository: there are implemented Database methods to call _show, _list and _update functions.
I find the official Python documentation a nightmare to navigate, but I love railsapi. Does anyone know of a browser for the Python standard library documentation with similar features to railsapi? Specifically the class browser sidebar and realtime search.
EDIT: I'm familiar with pydoc and it's not really much of an improvement over the online docs, IMO.
iPython, an interactive Python shell replacement (read: enhancement), includes the ?? operator, which gives you a convenient printout of the pydoc information.
For example:
In [5]: eval??
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in function eval>
Namespace: Python builtin
Docstring [source file open failed]:
eval(source[, globals[, locals]]) -> value
Evaluate the source in the context of globals and locals.
The source may be a string representing a Python expression
or a code object as returned by compile().
The globals must be a dictionary and locals can be any mapping,
defaulting to the current globals and locals.
If only globals is given, locals defaults to it.
Might not be exactly what you're looking for, but it's a great way to interact with Python's documentations.
Yes, there is an awesome documentation browser for Python, Django, JavaScript, iOS etc called Dash. It is only for OS X. You can download it from the Mac App Store. If you have a Mac then you'll love it.
There is also an open-source cross-platform alternative to dash: Zeal
It works with a global shortcut (Alt+Space), has instant search, supports many documentation formats and libraries (django, numpy, scipy, six, ...) and other languages.
I like pdoc. If you install pygments, it will even provide syntax highlighting. Just run it via pdoc --http and open localhost:8080 in your browser.